/*++

Module Name:

    device.c - Device handling events for example driver.

Abstract:

   This file contains the device entry points and callbacks.
    
Environment:

    Kernel-mode Driver Framework

--*/

#include "precomp.h"
#include "driver.h"
#include "device.tmh"

#ifdef ALLOC_PRAGMA
#pragma alloc_text (PAGE, dnsfilterCreateDevice)
#endif


WDFDEVICE    g_wdfControlDevice;

NTSTATUS
dnsfilterCreateDevice(
    _Inout_ PWDFDEVICE_INIT DeviceInit
    )
/*++

Routine Description:

    Worker routine called to create a device and its software resources.

Arguments:

    DeviceInit - Pointer to an opaque init structure. Memory for this
                    structure will be freed by the framework when the WdfDeviceCreate
                    succeeds. So don't access the structure after that point.

Return Value:

    NTSTATUS

--*/
{
    NTSTATUS                status;
    WDF_FILEOBJECT_CONFIG   fileConfig;
    DECLARE_CONST_UNICODE_STRING(ntDeviceName, DNSFILTER_DEVICE_NAME);
    DECLARE_CONST_UNICODE_STRING(symbolicLinkName, DNSFILTER_SYMBOLIC_NAME);
    PAGED_CODE();
    TraceEvents(
        TRACE_LEVEL_INFORMATION,
        TRACE_DEVICE,
        "%!FUNC! dnsfilterCreateDevice DeviceInit %p\n",
        DeviceInit
        );
    WdfDeviceInitSetIoType(DeviceInit, WdfDeviceIoBuffered);
    status = WdfDeviceInitAssignName(DeviceInit, &ntDeviceName);
    if (!NT_SUCCESS(status)) {
        TraceEvents(
            TRACE_LEVEL_ERROR,
            TRACE_DEVICE,
            "%!FUNC! WdfDeviceInitAssignName failed %!STATUS!",
            status
            );
        goto End;
    }
    WdfControlDeviceInitSetShutdownNotification(
        DeviceInit,
        dnsfilterShutdown,
        WdfDeviceShutdown
        );
    //
    // Initialize WDF_FILEOBJECT_CONFIG_INIT struct to tell the
    // framework whether you are interested in handling Create, Close and
    // Cleanup requests that gets generated when an application or another
    // kernel component opens an handle to the device. If you don't register
    // the framework default behaviour would be to complete these requests
    // with STATUS_SUCCESS. A driver might be interested in registering these
    // events if it wants to do security validation and also wants to maintain
    // per handle (fileobject) context.
    //
    WDF_FILEOBJECT_CONFIG_INIT(
        &fileConfig,
        dnsfilterEvtDeviceFileCreate,
        dnsfilterEvtFileClose,
        WDF_NO_EVENT_CALLBACK // not interested in Cleanup
        );
    fileConfig.FileObjectClass = (WDF_FILEOBJECT_CLASS) (WdfFileObjectWdfCannotUseFsContexts | WdfFileObjectCanBeOptional);
    WdfDeviceInitSetFileObjectConfig(DeviceInit,
        &fileConfig,
        WDF_NO_OBJECT_ATTRIBUTES);
    status = WdfDeviceCreate(&DeviceInit,
        WDF_NO_OBJECT_ATTRIBUTES,
        &g_wdfControlDevice);
    if (!NT_SUCCESS(status))
    {
        TraceEvents(
            TRACE_LEVEL_ERROR,
            TRACE_DEVICE,
            "%!FUNC! WdfDeviceCreate failed %!STATUS!",
            status
            );
        goto End;
    }
    //
    // Create a symbolic link for the control object so that usermode can open
    // the device.
    //
    status = WdfDeviceCreateSymbolicLink(
        g_wdfControlDevice,
        &symbolicLinkName
        );
    if (!NT_SUCCESS(status))
    {
        //
        // Control device will be deleted automatically by the framework.
        //
        TraceEvents(
            TRACE_LEVEL_ERROR,
            TRACE_DEVICE,
            "%!FUNC! WdfDeviceCreateSymbolicLink failed %!STATUS!",
            status
            );
        goto End;
    }
    //
    // Initialize the I/O Package and any Queues
    //
    status = dnsfilterQueueInitialize(g_wdfControlDevice);
    if (!NT_SUCCESS(status))
    {
        //
        // Control g_wdfControlDevice will be deleted automatically by the framework.
        //
        TraceEvents(
            TRACE_LEVEL_ERROR,
            TRACE_DEVICE,
            "%!FUNC! dnsfilterQueueInitialize failed %!STATUS!",
            status
            );
        goto End;
    }
    //
    // Control devices must notify WDF when they are done initializing.   I/O is
    // rejected until this call is made.
    //
    WdfControlFinishInitializing(g_wdfControlDevice);
End:
    //
    // If the device is created successfully, framework would clear the
    // DeviceInit value. Otherwise device create must have failed so we
    // should free the memory ourself.
    //
    if (DeviceInit != NULL) {
        WdfDeviceInitFree(DeviceInit);
    }
    TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "%!FUNC! Exit");
    return status;
}

VOID
dnsfilterShutdown(
WDFDEVICE Device
)
/*++

Routine Description:
Callback invoked when the machine is shutting down.  If you register for
a last chance shutdown notification you cannot do the following:
o Call any pageable routines
o Access pageable memory
o Perform any file I/O operations

If you register for a normal shutdown notification, all of these are
available to you.

This function implementation does nothing, but if you had any outstanding
file handles open, this is where you would close them.

Arguments:
Device - The device which registered the notification during init

Return Value:
None

--*/

{
    BOOLEAN bSignalWorkerThread;
    TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "%!FUNC! Entry");
    WdfObjectAcquireLock(Device);
    TraceEvents(
        TRACE_LEVEL_VERBOSE,
        TRACE_DEVICE,
        "%!FUNC! g_bDriverUnload = %!bool!",
        g_bDriverUnload
        );
    if (!g_bDriverUnload)
    {
        bSignalWorkerThread = IsListEmpty(&g_stPendedPacketsQueue);
        g_bDriverUnload = TRUE;
        if (bSignalWorkerThread)
        {
            KeSetEvent(
                &g_oWorkerEvent,
                0,
                FALSE
                );
        }
    }
    WdfObjectReleaseLock(Device);
    TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "%!FUNC! Exit");
}

VOID
dnsfilterEvtDeviceFileCreate(
IN WDFDEVICE        Device,
IN WDFREQUEST       Request,
IN WDFFILEOBJECT    FileObject
)
/*++

Routine Description:

The framework calls a driver's EvtDeviceFileCreate callback
when it receives an IRP_MJ_CREATE request.
The system sends this request when a user application opens the
device to perform an I/O operation, such as reading or writing a file.
This callback is called synchronously, in the context of the thread
that created the IRP_MJ_CREATE request.

Arguments:

Device - Handle to a framework device object.
FileObject - Pointer to fileobject that represents the open handle.
CreateParams - Parameters of IO_STACK_LOCATION for create

Return Value:

NT status code

--*/
{
    PUNICODE_STRING             fileName;
    NTSTATUS                    status = STATUS_SUCCESS;
    USHORT                      length = 0;
    PFLOW_DATA                  pFlowContext = NULL;
    WDF_OBJECT_ATTRIBUTES       stFlowContextAttributes;
    WDF_IO_QUEUE_CONFIG         stFlowContextQueueConfig;
    WDFDEVICE                   wdfDeviceObject = Device;
    TraceEvents(
        TRACE_LEVEL_INFORMATION,
        FILE_TRACE,
        "%!FUNC! line:%!LINE! %!LEVEL! Entry"
        );
    if (NULL == FileObject)
    {
        TraceEvents(
            TRACE_LEVEL_INFORMATION,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! Exit; No File Object (NULL == FileObject)"
            );
        goto End;
    }
    //
    // Parsed filename has "\" in the begining. The object manager strips
    // of all "\", except one, after the device name.
    //
    fileName = WdfFileObjectGetFileName(FileObject);
    length = fileName->Length;
    if (length > 0)
    {
        TraceEvents(
            TRACE_LEVEL_INFORMATION,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! dnsfilterEvtDeviceFileCreate %wZ",
            fileName
            );
    }
    else
    {
        TraceEvents(
            TRACE_LEVEL_INFORMATION,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! dnsfilterEvtDeviceFileCreate Device`s Root"
            );
        goto End;
    }
    WdfObjectAcquireLock(wdfDeviceObject);
    WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&stFlowContextAttributes, FLOW_DATA);
    status = WdfObjectAllocateContext(
        FileObject,
        &stFlowContextAttributes,
        (PVOID*) &pFlowContext
        );
    if (!NT_SUCCESS(status))
    {
        TraceEvents(
            TRACE_LEVEL_ERROR,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! WdfObjectAllocateContext failed with status %!STATUS!",
            status
            );
        WdfObjectReleaseLock(wdfDeviceObject);
        goto End;
    }
    pFlowContext->pThis = pFlowContext;
    pFlowContext->wdfFlowFileObject = FileObject;
    InsertTailList(
        &g_stOpenedFileList,
        &pFlowContext->stFileListEntry
        );
    WDF_IO_QUEUE_CONFIG_INIT(
        &stFlowContextQueueConfig,
        WdfIoQueueDispatchSequential
        );
    stFlowContextQueueConfig.AllowZeroLengthRequests = TRUE;
    stFlowContextQueueConfig.EvtIoDeviceControl = flowControlEvtIoDeviceControl;
    status = WdfIoQueueCreate(
        Device,
        &stFlowContextQueueConfig,
        WDF_NO_OBJECT_ATTRIBUTES,
        &pFlowContext->wdfFlowQueue
        );
    if (!NT_SUCCESS(status))
    {
        TraceEvents(
            TRACE_LEVEL_ERROR,
            TRACE_DEVICE,
            "%!FUNC! line:%!LINE! %!LEVEL! WdfIoQueueCreate failed with status %!STATUS!",
            status
            );
        WdfObjectReleaseLock(wdfDeviceObject);
        goto End;
    }
    WdfObjectReleaseLock(wdfDeviceObject);
End:
    WdfRequestComplete(Request, status);
    TraceEvents(
        TRACE_LEVEL_INFORMATION,
        FILE_TRACE,
        "%!FUNC! line:%!LINE! %!LEVEL! Exit"
        );
    return;
}

VOID
dnsfilterEvtFileClose(
IN WDFFILEOBJECT    wdfFlowFileObject
)

/*++

Routine Description:

EvtFileClose is called when all the handles represented by the FileObject
is closed and all the references to FileObject is removed. This callback
may get called in an arbitrary thread context instead of the thread that
called CloseHandle. If you want to delete any per FileObject context that
must be done in the context of the user thread that made the Create call,
you should do that in the EvtDeviceCleanp callback.

Arguments:

FileObject - Pointer to fileobject that represents the open handle.

Return Value:

VOID

--*/
{
    PFLOW_DATA          pFlowData;
    WDFREQUEST          wdfPendedRequest = NULL;
    NTSTATUS            status = STATUS_SUCCESS, status1;
    PMDL                _pMdl;
    WDFMEMORY           wdfOutputMemory;
    PNET_BUFFER_LIST    pNetBufferList;
    BOOLEAN             bInbound, bStateFinded = FALSE, bErrorState = FALSE;
    int                 i, nQueueIndx = 0;
    WSACMSGHDR*         _pControlData;
    UINT64              ullFlowId = 0;
    BOOLEAN             bListEmpty;
    WDFQUEUE            wdfPurgedQueue;
    WDFDEVICE           wdfDeviceObject;
    WDFQUEUE            wdfRequestQueue = NULL;
    BOOLEAN             bSignalWorkerThread;
    PLIST_ENTRY         pFileListEntry;
    WDFQUEUE            arRequestQueue[16] = { NULL };
    TraceEvents(
        TRACE_LEVEL_INFORMATION,
        FILE_TRACE,
        "%!FUNC! line:%!LINE! %!LEVEL! Entry"
        );
    wdfDeviceObject = g_wdfControlDevice;
    WdfObjectAcquireLock(wdfDeviceObject);
    if (NULL == wdfFlowFileObject)
    {
        TraceEvents(
            TRACE_LEVEL_ERROR,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! g_bDriverUnload = %!bool!",
            g_bDriverUnload
            );
        if (!g_bDriverUnload)
        {
            bSignalWorkerThread = IsListEmpty(&g_stPendedPacketsQueue);
            g_bDriverUnload = TRUE;
            if (bSignalWorkerThread)
            {
                KeSetEvent(
                    &g_oWorkerEvent,
                    0,
                    FALSE
                    );
            }
        }
        TraceEvents(
            TRACE_LEVEL_ERROR,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! Exit (NULL == wdfFlowFileObject)"
            );
        WdfObjectReleaseLock(wdfDeviceObject);
        return;
    }
    pFlowData = WdfObjectGetTypedContext(
        wdfFlowFileObject,
        FLOW_DATA
        );
    if (NULL == pFlowData)
    {
        TraceEvents(
            TRACE_LEVEL_INFORMATION,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! Close device root file. g_bDriverUnload = %!bool!",
            g_bDriverUnload
            );
        if (!IsListEmpty(&g_stOpenedFileList))
        {
            TraceEvents(
                TRACE_LEVEL_WARNING,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! g_stOpenedFileList is not empty."
                );
            if (!g_bDriverUnload)
            {
                bSignalWorkerThread = IsListEmpty(&g_stPendedPacketsQueue);
                g_bDriverUnload = TRUE;
                if (bSignalWorkerThread)
                {
                    KeSetEvent(
                        &g_oWorkerEvent,
                        0,
                        FALSE
                        );
                }
            }
            WdfObjectReleaseLock(wdfDeviceObject);
            KeWaitForSingleObject(
                &g_oWorkerDoneEvent,
                Executive,
                KernelMode,
                FALSE,
                NULL
                );
            KeClearEvent(&g_oWorkerDoneEvent);
            WdfObjectAcquireLock(wdfDeviceObject);
            while (!IsListEmpty(&g_stOpenedFileList))
            {
                PFILE_OBJECT    pFileObject;
                nQueueIndx = 0;
                bErrorState = FALSE;
                pFileListEntry = RemoveTailList(&g_stOpenedFileList);
                pFlowData = CONTAINING_RECORD(pFileListEntry, FLOW_DATA, stFileListEntry);
                ASSERT(NULL != pFlowData);
                ASSERT(NULL != pFlowData->wdfFlowFileObject);
                pFileObject = WdfFileObjectWdmGetFileObject(pFlowData->wdfFlowFileObject);
                ASSERT(NULL != pFileObject);
                TraceEvents(
                    TRACE_LEVEL_WARNING,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! Non closed file \"%ws\"",
                    pFileObject->FileName.Buffer
                    );
                ASSERT(NULL != pFlowData->pThis);
                ASSERT(pFlowData == pFlowData->pThis);
                ullFlowId = pFlowData->flowHandle;
                i = 0;
                switch (pFlowData->arContextStateStack[i])
                {
                case csFlowDeleted:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csFlowDeleted\""
                        );
                    break;
                case csTcpReplaceResponceDone:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceResponceDone\""
                        );
                    goto _continue_57;
                case csTcpPermitResponceDone:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitResponceDone\""
                        );
                _continue_57:
                    wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    break;
                case csTcpReplaceResponcePended:
                    ASSERT(IsListEmpty(&g_stPendedPacketsQueue));
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceResponcePended\""
                        );
                    goto _responce_done_01;
                case csTcpWaitReplaceResponceDone:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReplaceResponceDone\""
                        );
                _responce_done_01:
                    pNetBufferList = pFlowData->pTcpResponceInjectBufferList;
                    if (NULL != pNetBufferList)
                    {
                        FwpsFreeNetBufferList(
                            pNetBufferList
                            );
                        pFlowData->pTcpResponceInjectBufferList = NULL;
                        _pMdl = pFlowData->pTcpResponceMdl;
                        ASSERT(NULL != _pMdl);
                        IoFreeMdl(_pMdl);
                        ExFreePoolWithTag(
                            _pMdl->MappedSystemVa,
                            POOL_TAG
                            );
                        pFlowData->pTcpResponceMdl = NULL;
                    }
                    wdfRequestQueue = pFlowData->wdfTcpResponceInjectQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    break;
                case csTcpWaitResponceInjectDone:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitResponceInjectDone\""
                        );
                    bInbound = (BOOLEAN) (FWP_DIRECTION_INBOUND == pFlowData->enPacketDirection);
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! bInbound = %!bool!",
                        bInbound
                        );
                    pNetBufferList = pFlowData->pTcpResponceInjectBufferList;
                    if (NULL != pNetBufferList)
                    {
                        FwpsFreeNetBufferList(
                            pNetBufferList
                            );
                        pFlowData->pTcpResponceInjectBufferList = NULL;
                        _pMdl = pFlowData->pTcpResponceMdl;
                        ASSERT(NULL != _pMdl);
                        IoFreeMdl(_pMdl);
                        ExFreePoolWithTag(
                            _pMdl->MappedSystemVa,
                            POOL_TAG
                            );
                        pFlowData->pTcpResponceMdl = NULL;
                    }
                    wdfRequestQueue = pFlowData->wdfTcpResponceInjectQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    if (bInbound)
                    {
                        pNetBufferList = pFlowData->pTcpQueryBufferList;
                        pFlowData->pTcpQueryBufferList = NULL;
                        if (NULL != pNetBufferList)
                        {
                            FwpsDiscardClonedStreamData(
                                pNetBufferList,
                                0,
                                FALSE
                                );
                        }
                    }
                    else
                    {
                        pNetBufferList = pFlowData->pTcpResponceBufferList;
                        pFlowData->pTcpResponceBufferList = NULL;
                        if (NULL != pNetBufferList)
                        {
                            FwpsDiscardClonedStreamData(
                                pNetBufferList,
                                0,
                                FALSE
                                );
                        }
                    }
                    break;
                case csTcpWaitNewMessageStarted:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitNewMessageStarted\""
                        );
                    switch (pFlowData->arContextStateStack[i + 1])
                    {
                    case csTcpWaitApprovalResponce:
                        TraceEvents(
                            TRACE_LEVEL_WARNING,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitApprovalResponce\""
                            );
                        pNetBufferList = pFlowData->pTcpResponceBufferList;
                        pFlowData->pTcpResponceBufferList = NULL;
                        if (NULL != pNetBufferList)
                        {
                            FwpsDiscardClonedStreamData(
                                pNetBufferList,
                                0,
                                FALSE
                                );
                        }
                        break;
                    case csTcpWaitReplaceResponce:
                        TraceEvents(
                            TRACE_LEVEL_WARNING,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReplaceResponce\""
                            );
                        break;
                    case csTcpResponceDiscarded:
                        TraceEvents(
                            TRACE_LEVEL_WARNING,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpResponceDiscarded\""
                            );
                        break;
                    default:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                            );
                        break;
                    }
                    wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    break;
                case csTcpResponceDiscarded:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpResponceDiscarded\""
                        );
                    break;
                case csTcpWaitReplaceResponce:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReplaceResponce\""
                        );
                    break;
                case csTcpPermitResponcePended:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitResponcePended\""
                        );
                    ASSERT(IsListEmpty(&g_stPendedPacketsQueue));
                    goto _wait_permit_responce_01;
                case csTcpWaitPermitResponce:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitPermitResponce\""
                        );
                _wait_permit_responce_01:
                    pNetBufferList = pFlowData->pTcpResponceBufferList;
                    pFlowData->pTcpResponceBufferList = NULL;
                    if (NULL != pNetBufferList)
                    {
                        FwpsFreeCloneNetBufferList(
                            pNetBufferList,
                            0
                            );
                    }
                    wdfRequestQueue = pFlowData->wdfTcpResponcePermitQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    break;
                case csTcpWaitApprovalResponce:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitApprovalResponce\""
                        );
                    goto _wait_query_inject_done_01;
                case csTcpWaitReadResponce:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReadResponce\""
                        );
                    goto _wait_query_inject_done_01;
                case csTcpWaitQueryInjectDone:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitQueryInjectDone\""
                        );
                _wait_query_inject_done_01:
                    pNetBufferList = pFlowData->pTcpResponceBufferList;
                    if (NULL != pNetBufferList)
                    {
                        FwpsDiscardClonedStreamData(
                            pNetBufferList,
                            0,
                            FALSE
                            );
                        pFlowData->pTcpResponceBufferList = NULL;
                    }
                    break;
                case csTcpResponceMoreData03:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpResponceMoreData03\""
                        );
                    wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    break;
                case csTcpResponceMoreData02:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpResponceMoreData02\""
                        );
                    wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    break;
                case csTcpResponceMoreData01:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpResponceMoreData01\""
                        );
                    switch (pFlowData->arContextStateStack[i + 1])
                    {
                    case csTcpPermitQueryDone:
                        TraceEvents(
                            TRACE_LEVEL_WARNING,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitQueryDone\""
                            );
                        goto _continue_01;
                    case csTcpReplaceQueryDone:
                        TraceEvents(
                            TRACE_LEVEL_WARNING,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceQueryDone\""
                            );
                        goto _continue_01;
                    case csTcpResponceMoreData01:
                        TraceEvents(
                            TRACE_LEVEL_WARNING,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpResponceMoreData01\""
                            );
                        goto _continue_01;
                    case csTcpResponceMoreData02:
                        TraceEvents(
                            TRACE_LEVEL_WARNING,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpResponceMoreData02\""
                            );
                    _continue_01:
                        wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    case csTcpPermitResponceDone:
                        TraceEvents(
                            TRACE_LEVEL_WARNING,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitResponceDone\""
                            );
                        goto _continue_02;
                    case csTcpReplaceResponceDone:
                        TraceEvents(
                            TRACE_LEVEL_WARNING,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceResponceDone\""
                            );
                    _continue_02:
                        wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    default:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                            );
                        wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    }
                    break;
                case csTcpReplaceQueryDone:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceQueryDone\""
                        );
                    wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    break;
                case csTcpReplaceQueryPended:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceQueryPended\""
                        );
                    ASSERT(IsListEmpty(&g_stPendedPacketsQueue));
                    goto _continue_03;
                case csTcpWaitReplaceQueryDone:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReplaceQueryDone\""
                        );
                _continue_03:
                    pNetBufferList = pFlowData->pTcpQueryInjectBufferList;
                    if (NULL != pNetBufferList)
                    {
                        FwpsFreeNetBufferList(
                            pNetBufferList
                            );
                        pFlowData->pTcpQueryInjectBufferList = NULL;
                        _pMdl = pFlowData->pTcpQueryMdl;
                        ASSERT(NULL != _pMdl);
                        IoFreeMdl(_pMdl);
                        ExFreePoolWithTag(
                            _pMdl->MappedSystemVa,
                            POOL_TAG
                            );
                        pFlowData->pTcpQueryMdl = NULL;
                    }
                    wdfRequestQueue = pFlowData->wdfTcpQueryInjectQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    break;
                case csTcpPermitQueryDone:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitQueryDone\""
                        );
                    wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    break;
                case csTcpPermitQueryPended:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitQueryPended\""
                        );
                    ASSERT(IsListEmpty(&g_stPendedPacketsQueue));
                    goto _continue_04;
                case csTcpWaitPermitQuery:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitPermitQuery\""
                        );
                _continue_04:
                    pNetBufferList = pFlowData->pTcpQueryBufferList;
                    if (NULL != pNetBufferList)
                    {
                        FwpsFreeCloneNetBufferList(
                            pNetBufferList,
                            0
                            );
                        pFlowData->pTcpQueryBufferList = NULL;
                    }
                    wdfRequestQueue = pFlowData->wdfTcpQueryPermitQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    break;
                case csTcpQueryDiscarded:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpQueryDiscarded\""
                        );
                    break;
                case csTcpWaitReplaceQuery:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReplaceQuery\""
                        );
                    break;
                case csTcpWaitResponceStarted:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitResponceStarted\""
                        );
                    wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    break;
                case csTcpWaitApprovalQuery:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitApprovalQuery\""
                        );
                    goto _continue_05;
                case csTcpWaitReadQuery:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReadQuery\""
                        );
                _continue_05:
                    pNetBufferList = pFlowData->pTcpQueryBufferList;
                    pFlowData->pTcpQueryBufferList = NULL;
                    if (NULL != pNetBufferList)
                    {
                        FwpsDiscardClonedStreamData(
                            pNetBufferList,
                            0,
                            FALSE
                            );
                    }
                    break;
                case csTcpQueryMoreData02:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpQueryMoreData02\""
                        );
                    switch (pFlowData->arContextStateStack[i + 1])
                    {
                    case csTcpQueryMoreData02:
                        TraceEvents(
                            TRACE_LEVEL_WARNING,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpQueryMoreData02\""
                            );
                        for (i = i + 2; i<20; i++)
                        {
                            if (csTcpQueryMoreData02 != pFlowData->arContextStateStack[i])
                            {
                                bStateFinded = TRUE;
                                break;
                            }
                        }
                        if (!bStateFinded)
                        {
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! Invalid stack of State machine"
                                );
                            break;
                        }
                        if (csTcpWaitReplaceResponceDone == pFlowData->arContextStateStack[i])
                        {
                            goto _elaborate_replace_responce_01;
                        }
                        else if (csTcpWaitPermitResponce == pFlowData->arContextStateStack[i])
                        {
                            goto _elaborate_permit_responce_01;
                        }
                        else
                        {
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! Invalid stack of State machine"
                                );
                            break;
                        }
                    case csTcpWaitReplaceResponceDone:
                        TraceEvents(
                            TRACE_LEVEL_WARNING,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReplaceResponceDone\""
                            );
                    _elaborate_replace_responce_01:
                        pNetBufferList = pFlowData->pTcpResponceInjectBufferList;
                        if (NULL != pNetBufferList)
                        {
                            FwpsFreeNetBufferList(
                                pNetBufferList
                                );
                            pFlowData->pTcpResponceInjectBufferList = NULL;
                            _pMdl = pFlowData->pTcpResponceMdl;
                            ASSERT(NULL != _pMdl);
                            IoFreeMdl(_pMdl);
                            ExFreePoolWithTag(
                                _pMdl->MappedSystemVa,
                                POOL_TAG
                                );
                            pFlowData->pTcpResponceMdl = NULL;
                        }
                        wdfRequestQueue = pFlowData->wdfTcpResponceInjectQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    case csTcpWaitPermitResponce:
                        TraceEvents(
                            TRACE_LEVEL_WARNING,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitPermitResponce\""
                            );
                    _elaborate_permit_responce_01:
                        pNetBufferList = pFlowData->pTcpResponceBufferList;
                        if (NULL != pNetBufferList)
                        {
                            FwpsFreeCloneNetBufferList(
                                pNetBufferList,
                                0
                                );
                            pFlowData->pTcpResponceBufferList = NULL;
                        }
                        wdfRequestQueue = pFlowData->wdfTcpResponcePermitQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    default:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                            );
                        break;
                    }
                    wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    break;
                case csTcpQueryMoreData01:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpQueryMoreData01\""
                        );
                    switch (pFlowData->arContextStateStack[i + 1])
                    {
                    case csTcpQueryMoreData01:
                        TraceEvents(
                            TRACE_LEVEL_WARNING,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpQueryMoreData01\""
                            );
                        for (i = i + 2; i<20; i++)
                        {
                            if (csTcpQueryMoreData01 != pFlowData->arContextStateStack[i])
                            {
                                bStateFinded = TRUE;
                                break;
                            }
                        }
                        if (!bStateFinded)
                        {
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! Invalid stack of State machine"
                                );
                            wdfRequestQueue = NULL;
                            break;
                        }
                        switch (pFlowData->arContextStateStack[i])
                        {
                        case csTcpPermitResponceDone:
                            TraceEvents(
                                TRACE_LEVEL_WARNING,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitResponceDone\""
                                );
                            goto _elaborate_responce_01;
                        case csTcpReplaceResponceDone:
                            TraceEvents(
                                TRACE_LEVEL_WARNING,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceResponceDone\""
                                );
                            goto _elaborate_responce_01;
                        case csTcpFlowEstablished:
                            TraceEvents(
                                TRACE_LEVEL_WARNING,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpFlowEstablished\""
                                );
                            goto _elaborate_query_01;
                        default:
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                                );
                            break;
                        }
                        break;
                    case csTcpReplaceResponceDone:
                        TraceEvents(
                            TRACE_LEVEL_WARNING,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceResponceDone\""
                            );
                        goto _elaborate_responce_01;
                    case csTcpPermitResponceDone:
                        TraceEvents(
                            TRACE_LEVEL_WARNING,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitResponceDone\""
                            );
                    _elaborate_responce_01:
                        wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    case csTcpFlowEstablished:
                        TraceEvents(
                            TRACE_LEVEL_WARNING,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpFlowEstablished\""
                            );
                    _elaborate_query_01:
                        wdfRequestQueue = pFlowData->wdfWaitDnsQueryQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    default:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                            );
                        break;
                    }
                    break;
                case csTcpFlowEstablished:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpFlowEstablished\""
                        );
                    goto _continue_06;
                case csUdpFlowEstablished:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpFlowEstablished\""
                        );
                _continue_06:
                    wdfRequestQueue = pFlowData->wdfWaitDnsQueryQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    break;
                case csUdpFlowDone:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpFlowDone\""
                        );
                    break;
                case csUdpReplaceResponcePended:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpReplaceResponcePended\""
                        );
                    ASSERT(IsListEmpty(&g_stPendedPacketsQueue));
                    goto _continue_07;
                case csUdpWaitReplaceResponceDone:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReplaceResponceDone\""
                        );
                _continue_07:
                    pNetBufferList = pFlowData->pUdpResponceReplaceBufferList;
                    pFlowData->pUdpResponceReplaceBufferList = NULL;
                    if (NULL != pNetBufferList)
                    {
                        FwpsFreeNetBufferList(
                            pNetBufferList
                            );
                        _pControlData = pFlowData->stUdpResponceSendParams.controlData;
                        if (NULL != _pControlData)
                        {
                            ExFreePoolWithTag(
                                _pControlData,
                                POOL_TAG
                                );
                        }
                        RtlZeroMemory(
                            &pFlowData->stUdpResponceSendParams,
                            sizeof(FWPS_TRANSPORT_SEND_PARAMS)
                            );
                    }
                    _pMdl = pFlowData->pUdpResponceMdl;
                    pFlowData->pUdpResponceMdl = NULL;
                    if (NULL != _pMdl)
                    {
                        IoFreeMdl(_pMdl);
                        ExFreePoolWithTag(
                            _pMdl->MappedSystemVa,
                            POOL_TAG
                            );
                    }
                    wdfRequestQueue = pFlowData->wdfUdpResponceReplaceQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    break;
                case csUdpWaitReplaceResponce:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReplaceResponce\""
                        );
                    goto _continue_08;
                case csUdpWaitApprovalResponce:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitApprovalResponce\""
                        );
                    goto _continue_08;
                case csUdpWaitReadResponce:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReadResponce\""
                        );
                _continue_08:
                    pNetBufferList = pFlowData->pUdpResponceBufferList;
                    pFlowData->pUdpResponceBufferList = NULL;
                    if (NULL != pNetBufferList)
                    {
                        FwpsDereferenceNetBufferList(
                            pNetBufferList,
                            FALSE
                            );
                    }
                    pNetBufferList = pFlowData->pUdpResponceCloneBufferList;
                    pFlowData->pUdpResponceCloneBufferList = NULL;
                    if (NULL != pNetBufferList)
                    {
                        FwpsFreeCloneNetBufferList(
                            pNetBufferList,
                            0
                            );
                    }
                    _pControlData = pFlowData->stUdpResponceSendParams.controlData;
                    if (NULL != _pControlData)
                    {
                        ExFreePoolWithTag(
                            _pControlData,
                            POOL_TAG
                            );
                    }
                    RtlZeroMemory(
                        &pFlowData->stUdpResponceSendParams,
                        sizeof(FWPS_TRANSPORT_SEND_PARAMS)
                        );
                    break;
                case csUdpPermitResponcePended:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpPermitResponcePended\""
                        );
                    ASSERT(IsListEmpty(&g_stPendedPacketsQueue));
                    goto _continue_09;
                case csUdpWaitPermitResponce:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitPermitResponce\""
                        );
                _continue_09:
                    pNetBufferList = pFlowData->pUdpResponceCloneBufferList;
                    pFlowData->pUdpResponceCloneBufferList = NULL;
                    if (NULL != pNetBufferList)
                    {
                        FwpsFreeCloneNetBufferList(
                            pNetBufferList,
                            0
                            );
                    }
                    _pControlData = pFlowData->stUdpResponceSendParams.controlData;
                    if (NULL != _pControlData)
                    {
                        ExFreePoolWithTag(
                            _pControlData,
                            POOL_TAG
                            );
                    }
                    RtlZeroMemory(
                        &pFlowData->stUdpResponceSendParams,
                        sizeof(FWPS_TRANSPORT_SEND_PARAMS)
                        );
                    wdfRequestQueue = pFlowData->wdfUdpResponcePermitQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    break;
                case csUdpWaitQueryInjectDone:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitQueryInjectDone\""
                        );
                    switch (pFlowData->arContextStateStack[i + 1])
                    {
                    case csUdpWaitReplaceQueryDone:
                        TraceEvents(
                            TRACE_LEVEL_WARNING,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitQueryInjectDone\""
                            );
                        pNetBufferList = pFlowData->pUdpQueryReplaceBufferList;
                        pFlowData->pUdpQueryReplaceBufferList = NULL;
                        if (NULL != pNetBufferList)
                        {
                            FwpsFreeNetBufferList(
                                pNetBufferList
                                );
                        }
                        _pMdl = pFlowData->pUdpQueryMdl;
                        pFlowData->pUdpQueryMdl = NULL;
                        if (NULL != _pMdl)
                        {
                            IoFreeMdl(_pMdl);
                            ExFreePoolWithTag(
                                _pMdl->MappedSystemVa,
                                POOL_TAG
                                );
                        }
                        wdfRequestQueue = pFlowData->wdfUdpQueryReplaceQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    case csUdpWaitPermitQuery:
                        TraceEvents(
                            TRACE_LEVEL_WARNING,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitPermitQuery\""
                            );
                        pNetBufferList = pFlowData->pUdpQueryCloneBufferList;
                        pFlowData->pUdpQueryCloneBufferList = NULL;
                        if (NULL != pNetBufferList)
                        {
                            FwpsFreeCloneNetBufferList(
                                pNetBufferList,
                                0
                                );
                        }
                        wdfRequestQueue = pFlowData->wdfUdpQueryPermitQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    default:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                            );
                        break;
                    }
                    break;
                case csUdpReplaceQueryDone:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpReplaceQueryDone\""
                        );
                    goto _continue_10;
                case csUdpPermitQueryDone:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpPermitQueryDone\""
                        );
                _continue_10:
                    wdfRequestQueue = pFlowData->wdfWaitUdpResponceQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    break;
                case csUdpQueryDiscarded:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpQueryDiscarded\""
                        );
                    break;
                case csUdpReplaceQueryPended:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpReplaceQueryPended\""
                        );
                    ASSERT(IsListEmpty(&g_stPendedPacketsQueue));
                    goto _continue_11;
                case csUdpWaitReplaceQueryDone:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReplaceQueryDone\""
                        );
                _continue_11:
                    pNetBufferList = pFlowData->pUdpQueryReplaceBufferList;
                    pFlowData->pUdpQueryReplaceBufferList = NULL;
                    if (NULL != pNetBufferList)
                    {
                        FwpsFreeNetBufferList(
                            pNetBufferList
                            );
                    }
                    _pMdl = pFlowData->pUdpQueryMdl;
                    pFlowData->pUdpQueryMdl = NULL;
                    if (NULL != _pMdl)
                    {
                        IoFreeMdl(_pMdl);
                        ExFreePoolWithTag(
                            _pMdl->MappedSystemVa,
                            POOL_TAG
                            );
                    }
                    wdfRequestQueue = pFlowData->wdfUdpQueryReplaceQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    wdfRequestQueue = pFlowData->wdfWaitUdpResponceQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    break;
                case csUdpWaitReplaceQuery:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReplaceQuery\""
                        );
                    goto _continue_12;
                case csUdpWaitApprovalQuery:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitApprovalQuery\""
                        );
                _continue_12:
                    pNetBufferList = pFlowData->pUdpQueryBufferList;
                    pFlowData->pUdpQueryBufferList = NULL;
                    if (NULL != pNetBufferList)
                    {
                        FwpsDereferenceNetBufferList(
                            pNetBufferList,
                            FALSE
                            );
                    }
                    break;
                case csUdpPermitQueryPended:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpPermitQueryPended\""
                        );
                    ASSERT(IsListEmpty(&g_stPendedPacketsQueue));
                    goto _continue_13;
                case csUdpWaitPermitQuery:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitPermitQuery\""
                        );
                _continue_13:
                    pNetBufferList = pFlowData->pUdpQueryCloneBufferList;
                    pFlowData->pUdpQueryCloneBufferList = NULL;
                    if (NULL != pNetBufferList)
                    {
                        FwpsFreeCloneNetBufferList(
                            pNetBufferList,
                            0
                            );
                    }
                    wdfRequestQueue = pFlowData->wdfUdpQueryPermitQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    wdfRequestQueue = pFlowData->wdfWaitUdpResponceQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    break;
                case csUdpWaitResponceStarted:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitResponceStarted\""
                        );
                    pNetBufferList = pFlowData->pUdpQueryBufferList;
                    pFlowData->pUdpQueryBufferList = NULL;
                    if (NULL != pNetBufferList)
                    {
                        FwpsDereferenceNetBufferList(
                            pNetBufferList,
                            FALSE
                            );
                    }
                    wdfRequestQueue = pFlowData->wdfWaitUdpResponceQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    break;
                case csUdpWaitReadQuery:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReadQuery\""
                        );
                    pNetBufferList = pFlowData->pUdpQueryBufferList;
                    pFlowData->pUdpQueryBufferList = NULL;
                    if (NULL != pNetBufferList)
                    {
                        FwpsDereferenceNetBufferList(
                            pNetBufferList,
                            FALSE
                            );
                    }
                    wdfRequestQueue = pFlowData->wdfWaitFlowEstablishedQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    break;
                case csDnsError:
                    TraceEvents(
                        TRACE_LEVEL_ERROR,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csDnsError\""
                        );
                    bErrorState = TRUE;
                    for (i = i + 1; i<20; i++)
                    {
                        if (csDnsError != pFlowData->arContextStateStack[i])
                        {
                            bStateFinded = TRUE;
                            break;
                        }
                    }
                    if (!bStateFinded)
                    {
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! Invalid stack of State machine"
                            );
                        break;
                    }
                    i++;
                    switch (pFlowData->arContextStateStack[i])
                    {
                    case csTcpReplaceResponceDone:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceResponceDone\""
                            );
                        goto _continue_14;
                    case csTcpPermitResponceDone:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitResponceDone\""
                            );
                    _continue_14:
                        wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    case csTcpWaitPermitResponce:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitPermitResponce\""
                            );
                    _elaborate_permit_responce_02:
                        pNetBufferList = pFlowData->pTcpResponceBufferList;
                        pFlowData->pTcpResponceBufferList = NULL;
                        if (NULL != pNetBufferList)
                        {
                            FwpsFreeCloneNetBufferList(
                                pNetBufferList,
                                0
                                );
                        }
                        wdfRequestQueue = pFlowData->wdfTcpResponcePermitQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    case csTcpWaitReplaceResponceDone:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReplaceResponceDone\""
                            );
                    _elaborate_replace_responce_02:
                        pNetBufferList = pFlowData->pTcpResponceInjectBufferList;
                        if (NULL != pNetBufferList)
                        {
                            FwpsFreeNetBufferList(
                                pNetBufferList
                                );
                            pFlowData->pTcpResponceInjectBufferList = NULL;
                            _pMdl = pFlowData->pTcpResponceMdl;
                            ASSERT(NULL != _pMdl);
                            IoFreeMdl(_pMdl);
                            ExFreePoolWithTag(
                                _pMdl->MappedSystemVa,
                                POOL_TAG
                                );
                            pFlowData->pTcpResponceMdl = NULL;
                        }
                        wdfRequestQueue = pFlowData->wdfTcpResponceInjectQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    case csTcpResponceMoreData03:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpResponceMoreData03\""
                            );
                        bStateFinded = FALSE;
                        for (i = i + 1; i<20; i++)
                        {
                            if (csTcpResponceMoreData03 != pFlowData->arContextStateStack[i])
                            {
                                bStateFinded = TRUE;
                                break;
                            }
                        }
                        if (!bStateFinded)
                        {
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! Invalid stack of State machine"
                                );
                            break;
                        }
                        switch (pFlowData->arContextStateStack[i])
                        {
                        case csTcpWaitPermitResponce:
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitPermitResponce\""
                                );
                            goto _elaborate_permit_responce_02;
                        case csTcpWaitReplaceResponceDone:
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReplaceResponceDone\""
                                );
                            goto _elaborate_replace_responce_02;
                        default:
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                                );
                            break;
                        }
                        wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    case csTcpPermitQueryDone:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitQueryDone\""
                            );
                        goto _continue_15;
                    case csTcpReplaceQueryDone:
                        TraceEvents(
                            TRACE_LEVEL_WARNING,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceQueryDone\""
                            );
                    _continue_15:
                        wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    case csTcpWaitPermitQuery:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitPermitQuery\""
                            );
                    _elaborate_permit_query_02:
                        pNetBufferList = pFlowData->pTcpQueryBufferList;
                        if (NULL != pNetBufferList)
                        {
                            FwpsFreeCloneNetBufferList(
                                pNetBufferList,
                                0
                                );
                            pFlowData->pTcpQueryBufferList = NULL;
                        }
                        wdfRequestQueue = pFlowData->wdfTcpQueryPermitQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    case csTcpWaitReplaceQueryDone:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReplaceQueryDone\""
                            );
                    _elaborate_replace_query_02:
                        pNetBufferList = pFlowData->pTcpQueryInjectBufferList;
                        if (NULL != pNetBufferList)
                        {
                            FwpsFreeNetBufferList(
                                pNetBufferList
                                );
                            pFlowData->pTcpQueryInjectBufferList = NULL;
                            _pMdl = pFlowData->pTcpQueryMdl;
                            ASSERT(NULL != _pMdl);
                            IoFreeMdl(_pMdl);
                            ExFreePoolWithTag(
                                _pMdl->MappedSystemVa,
                                POOL_TAG
                                );
                            pFlowData->pTcpQueryMdl = NULL;
                        }
                        wdfRequestQueue = pFlowData->wdfTcpQueryInjectQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    case csTcpResponceMoreData02:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpResponceMoreData02\""
                            );
                    _elaborate_more_data02_02:
                        bStateFinded = FALSE;
                        for (i = i + 1; i<20; i++)
                        {
                            if (csTcpResponceMoreData02 != pFlowData->arContextStateStack[i])
                            {
                                bStateFinded = TRUE;
                                break;
                            }
                        }
                        if (!bStateFinded)
                        {
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! Invalid stack of State machine"
                                );
                            break;
                        }
                        switch (pFlowData->arContextStateStack[i])
                        {
                        case csTcpWaitPermitQuery:
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitPermitQuery\""
                                );
                            goto _elaborate_permit_query_02;
                        case csTcpWaitReplaceQueryDone:
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReplaceQueryDone\""
                                );
                            goto _elaborate_replace_query_02;
                        default:
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                                );
                            break;
                        }
                        wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    case csTcpResponceMoreData01:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpResponceMoreData01\""
                            );
                        bStateFinded = FALSE;
                        for (i = i + 1; i<20; i++)
                        {
                            if (csTcpResponceMoreData01 != pFlowData->arContextStateStack[i])
                            {
                                bStateFinded = TRUE;
                                break;
                            }
                        }
                        if (!bStateFinded)
                        {
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! Invalid stack of State machine"
                                );
                            wdfRequestQueue = NULL;
                            break;
                        }
                        switch (pFlowData->arContextStateStack[i])
                        {
                        case csTcpResponceMoreData02:
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpResponceMoreData02\""
                                );
                            goto _elaborate_more_data02_02;
                        case csTcpPermitQueryDone:
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitQueryDone\""
                                );
                            goto _continue_16;
                        case csTcpReplaceQueryDone:
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceQueryDone\""
                                );
                        _continue_16:
                            wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
                            if (NULL != wdfRequestQueue)
                            {
                                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                                nQueueIndx++;
                                ASSERT(nQueueIndx < 16);
                            }
                            break;
                        case csTcpPermitResponceDone:
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitResponceDone\""
                                );
                            goto _continue_17;
                        case csTcpReplaceResponceDone:
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceResponceDone\""
                                );
                        _continue_17:
                            wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
                            if (NULL != wdfRequestQueue)
                            {
                                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                                nQueueIndx++;
                                ASSERT(nQueueIndx < 16);
                            }
                            break;
                        default:
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                                );
                            wdfRequestQueue = NULL;
                            break;
                        }
                        break;
                    case csTcpQueryMoreData01:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpQueryMoreData01\""
                            );
                        for (i = i + 1; i<20; i++)
                        {
                            if (csTcpQueryMoreData01 != pFlowData->arContextStateStack[i])
                            {
                                bStateFinded = TRUE;
                                break;
                            }
                        }
                        if (!bStateFinded)
                        {
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! Invalid stack of State machine"
                                );
                            wdfPendedRequest = NULL;
                            break;
                        }
                        switch (pFlowData->arContextStateStack[i])
                        {
                        case csTcpFlowEstablished:
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpQueryMoreData01\""
                                );
                            goto _elaborate_flow_establised_02;
                        case csTcpPermitResponceDone:
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitResponceDone\""
                                );
                            goto _continue_18;
                        case csTcpReplaceResponceDone:
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceResponceDone\""
                                );
                        _continue_18:
                            wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
                            pFlowData->wdfWaitTcpNewMessageQueue = NULL;
                            break;
                        default:
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                                );
                            wdfRequestQueue = NULL;
                            break;
                        }
                        break;
                    case csTcpFlowEstablished:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpFlowEstablished\""
                            );
                    _elaborate_flow_establised_02:
                        wdfRequestQueue = pFlowData->wdfWaitDnsQueryQueue;
                        pFlowData->wdfWaitDnsQueryQueue = NULL;
                        break;
                    case csUdpReplaceQueryDone:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpReplaceQueryDone\""
                            );
                        goto _continue_19;
                    case csUdpPermitQueryDone:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpPermitQueryDone\""
                            );
                    _continue_19:
                        wdfRequestQueue = pFlowData->wdfWaitUdpResponceQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    case csUdpPermitQueryPended:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpPermitQueryPended\""
                            );
                        ASSERT(IsListEmpty(&g_stPendedPacketsQueue));
                        goto _continue_20;
                    case csUdpWaitPermitQuery:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitPermitQuery\""
                            );
                    _continue_20:
                        pNetBufferList = pFlowData->pUdpQueryCloneBufferList;
                        pFlowData->pUdpQueryCloneBufferList = NULL;
                        if (NULL != pNetBufferList)
                        {
                            FwpsFreeCloneNetBufferList(
                                pNetBufferList,
                                0
                                );
                        }
                        wdfRequestQueue = pFlowData->wdfUdpQueryPermitQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        wdfRequestQueue = pFlowData->wdfWaitUdpResponceQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    case csUdpReplaceQueryPended:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpReplaceQueryPended\""
                            );
                        ASSERT(IsListEmpty(&g_stPendedPacketsQueue));
                        goto _continue_21;
                    case csUdpWaitReplaceQueryDone:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReplaceQueryDone\""
                            );
                    _continue_21:
                        pNetBufferList = pFlowData->pUdpQueryReplaceBufferList;
                        pFlowData->pUdpQueryReplaceBufferList = NULL;
                        if (NULL != pNetBufferList)
                        {
                            FwpsFreeNetBufferList(
                                pNetBufferList
                                );
                        }
                        _pMdl = pFlowData->pUdpQueryMdl;
                        pFlowData->pUdpQueryMdl = NULL;
                        if (NULL != _pMdl)
                        {
                            IoFreeMdl(_pMdl);
                            ExFreePoolWithTag(
                                _pMdl->MappedSystemVa,
                                POOL_TAG
                                );
                        }
                        wdfRequestQueue = pFlowData->wdfUdpQueryReplaceQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        wdfRequestQueue = pFlowData->wdfWaitUdpResponceQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    case csUdpWaitResponceStarted:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitResponceStarted\""
                            );
                        pNetBufferList = pFlowData->pUdpQueryBufferList;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        wdfRequestQueue = pFlowData->wdfWaitUdpResponceQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    case csUdpQueryDiscarded:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpQueryDiscarded\""
                            );
                        break;
                    case csUdpWaitQueryInjectDone:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitQueryInjectDone\""
                            );
                        switch (pFlowData->arContextStateStack[i+2])
                        {
                        case csUdpWaitReplaceQueryDone:
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReplaceQueryDone\""
                                );
                            pNetBufferList = pFlowData->pUdpQueryReplaceBufferList;
                            pFlowData->pUdpQueryReplaceBufferList = NULL;
                            if (NULL != pNetBufferList)
                            {
                                FwpsFreeNetBufferList(
                                    pNetBufferList
                                    );
                            }
                            _pMdl = pFlowData->pUdpQueryMdl;
                            pFlowData->pUdpQueryMdl = NULL;
                            if (NULL != _pMdl)
                            {
                                IoFreeMdl(_pMdl);
                                ExFreePoolWithTag(
                                    _pMdl->MappedSystemVa,
                                    POOL_TAG
                                    );
                            }
                            wdfRequestQueue = pFlowData->wdfUdpQueryReplaceQueue;
                            if (NULL != wdfRequestQueue)
                            {
                                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                                nQueueIndx++;
                                ASSERT(nQueueIndx < 16);
                            }
                            break;
                        case csUdpWaitPermitQuery:
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitPermitQuery\""
                                );
                            pNetBufferList = pFlowData->pUdpQueryCloneBufferList;
                            pFlowData->pUdpQueryCloneBufferList = NULL;
                            if (NULL != pNetBufferList)
                            {
                                FwpsFreeCloneNetBufferList(
                                    pNetBufferList,
                                    0
                                    );
                            }
                            wdfRequestQueue = pFlowData->wdfUdpQueryPermitQueue;
                            if (NULL != wdfRequestQueue)
                            {
                                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                                nQueueIndx++;
                                ASSERT(nQueueIndx < 16);
                            }
                            break;
                        default:
                            TraceEvents(
                                TRACE_LEVEL_ERROR,
                                FILE_TRACE,
                                "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                                );
                            break;
                        }
                        break;
                    case csUdpWaitReplaceResponce:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReplaceResponce\""
                            );
                        goto _continue_22;
                    case csUdpWaitApprovalResponce:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitApprovalResponce\""
                            );
                        goto _continue_22;
                    case csUdpWaitReadResponce:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReadResponce\""
                            );
                    _continue_22:
                        pNetBufferList = pFlowData->pUdpResponceBufferList;
                        pFlowData->pUdpResponceBufferList = NULL;
                        if (NULL != pNetBufferList)
                        {
                            FwpsDereferenceNetBufferList(
                                pNetBufferList,
                                FALSE
                                );
                        }
                        pNetBufferList = pFlowData->pUdpResponceCloneBufferList;
                        pFlowData->pUdpResponceCloneBufferList = NULL;
                        if (NULL != pNetBufferList)
                        {
                            FwpsFreeCloneNetBufferList(
                                pNetBufferList,
                                0
                                );
                        }
                        _pControlData = pFlowData->stUdpResponceSendParams.controlData;
                        if (NULL != _pControlData)
                        {
                            ExFreePoolWithTag(
                                _pControlData,
                                POOL_TAG
                                );
                        }
                        RtlZeroMemory(
                            &pFlowData->stUdpResponceSendParams,
                            sizeof(FWPS_TRANSPORT_SEND_PARAMS)
                            );
                        break;
                    case csUdpPermitResponcePended:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpPermitResponcePended\""
                            );
                        ASSERT(IsListEmpty(&g_stPendedPacketsQueue));
                        goto _continue_23;
                    case csUdpWaitPermitResponce:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitPermitResponce\""
                            );
                    _continue_23:
                        pNetBufferList = pFlowData->pUdpResponceCloneBufferList;
                        pFlowData->pUdpResponceCloneBufferList = NULL;
                        if (NULL != pNetBufferList)
                        {
                            FwpsFreeCloneNetBufferList(
                                pNetBufferList,
                                0
                                );
                        }
                        _pControlData = pFlowData->stUdpResponceSendParams.controlData;
                        if (NULL != _pControlData)
                        {
                            ExFreePoolWithTag(
                                _pControlData,
                                POOL_TAG
                                );
                        }
                        RtlZeroMemory(
                            &pFlowData->stUdpResponceSendParams,
                            sizeof(FWPS_TRANSPORT_SEND_PARAMS)
                            );
                        wdfRequestQueue = pFlowData->wdfUdpResponcePermitQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    case csUdpReplaceResponcePended:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpReplaceResponcePended\""
                            );
                        ASSERT(IsListEmpty(&g_stPendedPacketsQueue));
                        goto _continue_24;
                    case csUdpWaitReplaceResponceDone:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReplaceResponceDone\""
                            );
                    _continue_24:
                        pNetBufferList = pFlowData->pUdpResponceReplaceBufferList;
                        pFlowData->pUdpResponceReplaceBufferList = NULL;
                        if (NULL != pNetBufferList)
                        {
                            FwpsFreeNetBufferList(
                                pNetBufferList
                                );
                            _pControlData = pFlowData->stUdpResponceSendParams.controlData;
                            if (NULL != _pControlData)
                            {
                                ExFreePoolWithTag(
                                    _pControlData,
                                    POOL_TAG
                                    );
                            }
                            RtlZeroMemory(
                                &pFlowData->stUdpResponceSendParams,
                                sizeof(FWPS_TRANSPORT_SEND_PARAMS)
                                );
                        }
                        _pMdl = pFlowData->pUdpResponceMdl;
                        pFlowData->pUdpResponceMdl = NULL;
                        if (NULL != _pMdl)
                        {
                            IoFreeMdl(_pMdl);
                            ExFreePoolWithTag(
                                _pMdl->MappedSystemVa,
                                POOL_TAG
                                );
                        }
                        wdfRequestQueue = pFlowData->wdfUdpResponceReplaceQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    case csUdpWaitReplaceQuery:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReplaceQuery\""
                            );
                        goto _continue_25;
                    case csUdpWaitApprovalQuery:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitApprovalQuery\""
                            );
                    _continue_25:
                        pNetBufferList = pFlowData->pUdpQueryBufferList;
                        pFlowData->pUdpQueryBufferList = NULL;
                        if (NULL != pNetBufferList)
                        {
                            FwpsDereferenceNetBufferList(
                                pNetBufferList,
                                FALSE
                                );
                        }
                        break;
                    case csUdpWaitReadQuery:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReadQuery\""
                            );
                        pNetBufferList = pFlowData->pUdpQueryBufferList;
                        pFlowData->pUdpQueryBufferList = NULL;
                        if (NULL != pNetBufferList)
                        {
                            FwpsDereferenceNetBufferList(
                                pNetBufferList,
                                FALSE
                                );
                        }
                        wdfRequestQueue = pFlowData->wdfWaitFlowEstablishedQueue;
                        if (NULL != wdfRequestQueue)
                        {
                            arRequestQueue[nQueueIndx] = wdfRequestQueue;
                            nQueueIndx++;
                            ASSERT(nQueueIndx < 16);
                        }
                        break;
                    default:
                        TraceEvents(
                            TRACE_LEVEL_ERROR,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                            );
                        break;
                    }
                    break;
                case csWaitFlowEstablishedStarted:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csWaitFlowEstablishedStarted\""
                        );
                    wdfRequestQueue = pFlowData->wdfWaitFlowEstablishedQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    bListEmpty = RemoveEntryList(
                        &pFlowData->listEntry
                        );
                    wdfRequestQueue = pFlowData->wdfWaitDnsQueryQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    break;
                case csWaitFlowDoneStarted:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csWaitFlowDoneStarted\""
                        );
                    goto _continue_26;
                case csWaitQueryStarted:
                    TraceEvents(
                        TRACE_LEVEL_WARNING,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csWaitQueryStarted\""
                        );
                _continue_26:
                    wdfRequestQueue = pFlowData->wdfWaitDnsQueryQueue;
                    if (NULL != wdfRequestQueue)
                    {
                        arRequestQueue[nQueueIndx] = wdfRequestQueue;
                        nQueueIndx++;
                        ASSERT(nQueueIndx < 16);
                    }
                    break;
                default:
                    TraceEvents(
                        TRACE_LEVEL_ERROR,
                        FILE_TRACE,
                        "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                        );
                    break;
                }
                if (!bErrorState)
                {
                    if (0 != ullFlowId)
                    {
                        WdfObjectReleaseLock(wdfDeviceObject);
                        if (IPPROTO_TCP == pFlowData->enIpProto)
                        {
                            if (pFlowData->bIPv6)
                            {
                                status = FwpsFlowRemoveContext(
                                    ullFlowId,
                                    FWPS_LAYER_STREAM_V6,
                                    g_nStreamIdV6
                                    );
                            }
                            else
                            {
                                status = FwpsFlowRemoveContext(
                                    ullFlowId,
                                    FWPS_LAYER_STREAM_V4,
                                    g_nStreamId
                                    );
                            }
                        }
                        else if (IPPROTO_UDP == pFlowData->enIpProto)
                        {
                            if (pFlowData->bIPv6)
                            {
                                status = FwpsFlowRemoveContext(
                                    ullFlowId,
                                    FWPS_LAYER_DATAGRAM_DATA_V6,
                                    g_nDatagramIdV6
                                    );
                            }
                            else
                            {
                                status = FwpsFlowRemoveContext(
                                    ullFlowId,
                                    FWPS_LAYER_DATAGRAM_DATA_V4,
                                    g_nDatagramId
                                    );
                            }
                        }
                        else
                        {
                            ASSERT(FALSE);
                        }
                        TraceEvents(
                            TRACE_LEVEL_WARNING,
                            FILE_TRACE,
                            "%!FUNC! line:%!LINE! %!LEVEL! \"FwpsFlowRemoveContext\" return %!STATUS!",
                            status
                            );
                        if ((STATUS_SUCCESS == status) || (STATUS_PENDING == status))
                        {
                            WdfObjectAcquireLock(wdfDeviceObject);
                            wdfPurgedQueue = pFlowData->wdfFlowQueue;
                            pFlowData->wdfFlowQueue = NULL;
                            if (NULL != wdfPurgedQueue)
                            {
                                WdfIoQueuePurge(
                                    wdfPurgedQueue,
                                    NULL,
                                    NULL
                                    );
                                WdfObjectDelete(
                                    wdfPurgedQueue
                                    );
                            }
                            continue;
                        }
                        WdfObjectAcquireLock(wdfDeviceObject);
                        status1 = status;
                        wdfRequestQueue = pFlowData->wdfWaitFlowDoneQueue;
                        pFlowData->wdfWaitFlowDoneQueue = NULL;
                        if (NULL != wdfRequestQueue)
                        {
                            status = WdfIoQueueRetrieveNextRequest(
                                wdfRequestQueue,
                                &wdfPendedRequest
                                );
                            if (NT_SUCCESS(status))
                            {
                                status = WdfRequestRetrieveOutputMemory(
                                    wdfPendedRequest,
                                    &wdfOutputMemory
                                    );
                                ASSERT(NT_SUCCESS(status));
                                status = WdfMemoryCopyFromBuffer(
                                    wdfOutputMemory,
                                    0,
                                    pFlowData,
                                    sizeof(FLOW_DATA)
                                    );
                                ASSERT(NT_SUCCESS(status));
                                WdfRequestCompleteWithInformation(
                                    wdfPendedRequest,
                                    status1,
                                    sizeof(FLOW_DATA)
                                    );
                            }
                            WdfObjectDelete(wdfRequestQueue);
                        }
                    }
                    for (i = 0; i < nQueueIndx; i++)
                    {
                        status = WdfIoQueueRetrieveNextRequest(
                            wdfRequestQueue,
                            &wdfPendedRequest
                            );
                        if (NT_SUCCESS(status))
                        {
                            WdfRequestCompleteWithInformation(
                                wdfPendedRequest,
                                STATUS_CANCELLED,
                                0
                                );
                        }
                        WdfObjectDelete(wdfRequestQueue);
                    }
                    wdfPurgedQueue = pFlowData->wdfFlowQueue;
                    pFlowData->wdfFlowQueue = NULL;
                    if (NULL != wdfPurgedQueue)
                    {
                        WdfIoQueuePurge(
                            wdfPurgedQueue,
                            NULL,
                            NULL
                            );
                        WdfObjectDelete(
                            wdfPurgedQueue
                            );
                    }
                    continue;
                }
                for (i = 0; i < nQueueIndx; i++)
                {
                    status = WdfIoQueueRetrieveNextRequest(
                        wdfRequestQueue,
                        &wdfPendedRequest
                        );
                    if (NT_SUCCESS(status))
                    {
                        WdfRequestCompleteWithInformation(
                            wdfPendedRequest,
                            STATUS_CANCELLED,
                            0
                            );
                    }
                    WdfObjectDelete(wdfRequestQueue);
                }
                wdfPurgedQueue = pFlowData->wdfFlowQueue;
                pFlowData->wdfFlowQueue = NULL;
                if (NULL != wdfPurgedQueue)
                {
                    WdfIoQueuePurge(
                        wdfPurgedQueue,
                        NULL,
                        NULL
                        );
                    WdfObjectDelete(
                        wdfPurgedQueue
                        );
                }
            }
        }
        WdfObjectReleaseLock(wdfDeviceObject);
        TraceEvents(
            TRACE_LEVEL_INFORMATION,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! Exit (NULL == pFlowData)"
            );
        return;
    }
    ASSERT(NULL != pFlowData->pThis);
    if (pFlowData != pFlowData->pThis)
    {
        TraceEvents(
            TRACE_LEVEL_ERROR,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! Exit (pFlowData != pFlowData->pThis)"
            );
        return;
    }
    ullFlowId = pFlowData->flowHandle;
    i = 0;
    switch (pFlowData->arContextStateStack[i])
    {
    case csFlowDeleted:
        TraceEvents(
            TRACE_LEVEL_INFORMATION,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csFlowDeleted\""
            );
        break;
    case csTcpReplaceResponceDone:
        TraceEvents(
            TRACE_LEVEL_INFORMATION,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceResponceDone\""
            );
        goto _continue_27;
    case csTcpPermitResponceDone:
        TraceEvents(
            TRACE_LEVEL_INFORMATION,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitResponceDone\""
            );
    _continue_27:
        wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        break;
    case csTcpReplaceResponcePended:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceResponcePended\""
            );
        bListEmpty = RemoveEntryList(&pFlowData->threadListEntry);
        goto _continue_28;
    case csTcpWaitReplaceResponceDone:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReplaceResponceDone\""
            );
    _continue_28:
        pNetBufferList = pFlowData->pTcpResponceInjectBufferList;
        if (NULL != pNetBufferList)
        {
            FwpsFreeNetBufferList(
                pNetBufferList
                );
            pFlowData->pTcpResponceInjectBufferList = NULL;
            _pMdl = pFlowData->pTcpResponceMdl;
            ASSERT(NULL != _pMdl);
            IoFreeMdl(_pMdl);
            ExFreePoolWithTag(
                _pMdl->MappedSystemVa,
                POOL_TAG
                );
            pFlowData->pTcpResponceMdl = NULL;
        }
        wdfRequestQueue = pFlowData->wdfTcpResponceInjectQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        break;
    case csTcpWaitResponceInjectDone:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitResponceInjectDone\""
            );
        bInbound = (BOOLEAN) (FWP_DIRECTION_INBOUND == pFlowData->enPacketDirection);
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! bInbound = %!bool!",
            bInbound
            );
        pNetBufferList = pFlowData->pTcpResponceInjectBufferList;
        if (NULL != pNetBufferList)
        {
            FwpsFreeNetBufferList(
                pNetBufferList
                );
            pFlowData->pTcpResponceInjectBufferList = NULL;
            _pMdl = pFlowData->pTcpResponceMdl;
            ASSERT(NULL != _pMdl);
            IoFreeMdl(_pMdl);
            ExFreePoolWithTag(
                _pMdl->MappedSystemVa,
                POOL_TAG
                );
            pFlowData->pTcpResponceMdl = NULL;
        }
        wdfRequestQueue = pFlowData->wdfTcpResponceInjectQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        if (bInbound)
        {
            pNetBufferList = pFlowData->pTcpQueryBufferList;
            pFlowData->pTcpQueryBufferList = NULL;
            if (NULL != pNetBufferList)
            {
                FwpsDiscardClonedStreamData(
                    pNetBufferList,
                    0,
                    FALSE
                    );
            }
        }
        else
        {
            pNetBufferList = pFlowData->pTcpResponceBufferList;
            pFlowData->pTcpResponceBufferList = NULL;
            if (NULL != pNetBufferList)
            {
                FwpsDiscardClonedStreamData(
                    pNetBufferList,
                    0,
                    FALSE
                    );
            }
        }
        break;
    case csTcpWaitNewMessageStarted:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitNewMessageStarted\""
            );
        switch (pFlowData->arContextStateStack[i + 1])
        {
        case csTcpWaitApprovalResponce:
            TraceEvents(
                TRACE_LEVEL_WARNING,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitApprovalResponce\""
                );
            pNetBufferList = pFlowData->pTcpResponceBufferList;
            pFlowData->pTcpResponceBufferList = NULL;
            if (NULL != pNetBufferList)
            {
                FwpsDiscardClonedStreamData(
                    pNetBufferList,
                    0,
                    FALSE
                    );
            }
            break;
        case csTcpWaitReplaceResponce:
            TraceEvents(
                TRACE_LEVEL_WARNING,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReplaceResponce\""
                );
            break;
        case csTcpResponceDiscarded:
            TraceEvents(
                TRACE_LEVEL_WARNING,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpResponceDiscarded\""
                );
            break;
        default:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                );
            break;
        }
        wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        break;
    case csTcpResponceDiscarded:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpResponceDiscarded\""
            );
        break;
    case csTcpWaitReplaceResponce:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReplaceResponce\""
            );
        break;
    case csTcpPermitResponcePended:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitResponcePended\""
            );
        bListEmpty = RemoveEntryList(&pFlowData->threadListEntry);
        goto _continue_29;
    case csTcpWaitPermitResponce:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitPermitResponce\""
            );
    _continue_29:
        pNetBufferList = pFlowData->pTcpResponceBufferList;
        pFlowData->pTcpResponceBufferList = NULL;
        if (NULL != pNetBufferList)
        {
            FwpsFreeCloneNetBufferList(
                pNetBufferList,
                0
                );
        }
        wdfRequestQueue = pFlowData->wdfTcpResponcePermitQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        break;
    case csTcpWaitApprovalResponce:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitApprovalResponce\""
            );
        goto _continue_30;
    case csTcpWaitReadResponce:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReadResponce\""
            );
        goto _continue_30;
    case csTcpWaitQueryInjectDone:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitQueryInjectDone\""
            );
    _continue_30:
        pNetBufferList = pFlowData->pTcpResponceBufferList;
        if (NULL != pNetBufferList)
        {
            FwpsDiscardClonedStreamData(
                pNetBufferList,
                0,
                FALSE
                );
            pFlowData->pTcpResponceBufferList = NULL;
        }
        break;
    case csTcpResponceMoreData03:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpResponceMoreData03\""
            );
        wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        break;
    case csTcpResponceMoreData02:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpResponceMoreData02\""
            );
        wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        break;
    case csTcpResponceMoreData01:
        TraceEvents(
            TRACE_LEVEL_INFORMATION,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpResponceMoreData01\""
            );
        switch (pFlowData->arContextStateStack[i + 1])
        {
        case csTcpPermitQueryDone:
            TraceEvents(
                TRACE_LEVEL_WARNING,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitQueryDone\""
                );
            goto _continue_31;
        case csTcpReplaceQueryDone:
            TraceEvents(
                TRACE_LEVEL_WARNING,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceQueryDone\""
                );
            goto _continue_31;
        case csTcpResponceMoreData01:
            TraceEvents(
                TRACE_LEVEL_WARNING,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpResponceMoreData01\""
                );
            goto _continue_31;
        case csTcpResponceMoreData02:
            TraceEvents(
                TRACE_LEVEL_WARNING,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpResponceMoreData02\""
                );
        _continue_31:
            wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        case csTcpPermitResponceDone:
            TraceEvents(
                TRACE_LEVEL_WARNING,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitResponceDone\""
                );
            goto _continue_32;
        case csTcpReplaceResponceDone:
            TraceEvents(
                TRACE_LEVEL_WARNING,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceResponceDone\""
                );
        _continue_32:
            wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        default:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                );
            wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        }
        break;
    case csTcpReplaceQueryDone:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceQueryDone\""
            );
        wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        break;
    case csTcpReplaceQueryPended:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceQueryPended\""
            );
        bListEmpty = RemoveEntryList(&pFlowData->threadListEntry);
        goto _continue_33;
    case csTcpWaitReplaceQueryDone:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReplaceQueryDone\""
            );
    _continue_33:
        pNetBufferList = pFlowData->pTcpQueryInjectBufferList;
        if (NULL != pNetBufferList)
        {
            FwpsFreeNetBufferList(
                pNetBufferList
                );
            pFlowData->pTcpQueryInjectBufferList = NULL;
            _pMdl = pFlowData->pTcpQueryMdl;
            ASSERT(NULL != _pMdl);
            IoFreeMdl(_pMdl);
            ExFreePoolWithTag(
                _pMdl->MappedSystemVa,
                POOL_TAG
                );
            pFlowData->pTcpQueryMdl = NULL;
        }
        wdfRequestQueue = pFlowData->wdfTcpQueryInjectQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        break;
    case csTcpPermitQueryDone:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitQueryDone\""
            );
        wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        break;
    case csTcpPermitQueryPended:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitQueryPended\""
            );
        bListEmpty = RemoveEntryList(&pFlowData->threadListEntry);
        goto _continue_34;
    case csTcpWaitPermitQuery:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitPermitQuery\""
            );
    _continue_34:
        pNetBufferList = pFlowData->pTcpQueryBufferList;
        if (NULL != pNetBufferList)
        {
            FwpsFreeCloneNetBufferList(
                pNetBufferList,
                0
                );
            pFlowData->pTcpQueryBufferList = NULL;
        }
        wdfRequestQueue = pFlowData->wdfTcpQueryPermitQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        break;
    case csTcpQueryDiscarded:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpQueryDiscarded\""
            );
        break;
    case csTcpWaitReplaceQuery:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReplaceQuery\""
            );
        break;
    case csTcpWaitResponceStarted:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitResponceStarted\""
            );
        wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        break;
    case csTcpWaitApprovalQuery:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitApprovalQuery\""
            );
        goto _continue_35;
    case csTcpWaitReadQuery:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReadQuery\""
            );
    _continue_35:
        pNetBufferList = pFlowData->pTcpQueryBufferList;
        pFlowData->pTcpQueryBufferList = NULL;
        if (NULL != pNetBufferList)
        {
            FwpsDiscardClonedStreamData(
                pNetBufferList,
                0,
                FALSE
                );
        }
        break;
    case csTcpQueryMoreData02:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpQueryMoreData02\""
            );
        switch (pFlowData->arContextStateStack[i + 1])
        {
        case csTcpQueryMoreData02:
            TraceEvents(
                TRACE_LEVEL_WARNING,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpQueryMoreData02\""
                );
            for (i = i + 2; i<20; i++)
            {
                if (csTcpQueryMoreData02 != pFlowData->arContextStateStack[i])
                {
                    bStateFinded = TRUE;
                    break;
                }
            }
            if (!bStateFinded)
            {
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! Invalid stack of State machine"
                    );
                break;
            }
            if (csTcpWaitReplaceResponceDone == pFlowData->arContextStateStack[i])
            {
                goto _elaborate_replace_responce_03;
            }
            else if (csTcpWaitPermitResponce == pFlowData->arContextStateStack[i])
            {
                goto _elaborate_permit_responce_03;
            }
            else
            {
                ASSERT(FALSE);
                break;
            }
        case csTcpWaitReplaceResponceDone:
            TraceEvents(
            TRACE_LEVEL_WARNING,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReplaceResponceDone\""
                );
        _elaborate_replace_responce_03:
            pNetBufferList = pFlowData->pTcpResponceInjectBufferList;
            if (NULL != pNetBufferList)
            {
                FwpsFreeNetBufferList(
                    pNetBufferList
                    );
                pFlowData->pTcpResponceInjectBufferList = NULL;
                _pMdl = pFlowData->pTcpResponceMdl;
                ASSERT(NULL != _pMdl);
                IoFreeMdl(_pMdl);
                ExFreePoolWithTag(
                    _pMdl->MappedSystemVa,
                    POOL_TAG
                    );
                pFlowData->pTcpResponceMdl = NULL;
            }
            wdfRequestQueue = pFlowData->wdfTcpResponceInjectQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        case csTcpWaitPermitResponce:
            TraceEvents(
                TRACE_LEVEL_WARNING,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitPermitResponce\""
                );
        _elaborate_permit_responce_03:
            pNetBufferList = pFlowData->pTcpResponceBufferList;
            if (NULL != pNetBufferList)
            {
                FwpsFreeCloneNetBufferList(
                    pNetBufferList,
                    0
                    );
                pFlowData->pTcpResponceBufferList = NULL;
            }
            wdfRequestQueue = pFlowData->wdfTcpResponcePermitQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        default:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                );
            break;
        }
        wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        break;
    case csTcpQueryMoreData01:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpQueryMoreData01\""
            );
        switch (pFlowData->arContextStateStack[i + 1])
        {
        case csTcpQueryMoreData01:
            TraceEvents(
                TRACE_LEVEL_WARNING,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpQueryMoreData01\""
                );
            for (i = i + 2; i<20; i++)
            {
                if (csTcpQueryMoreData01 != pFlowData->arContextStateStack[i])
                {
                    bStateFinded = TRUE;
                    break;
                }
            }
            if (!bStateFinded)
            {
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! Invalid stack of State machine"
                    );
                break;
            }
            switch (pFlowData->arContextStateStack[i])
            {
            case csTcpPermitResponceDone:
                TraceEvents(
                    TRACE_LEVEL_WARNING,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitResponceDone\""
                    );
                goto _elaborate_responce_02;
            case csTcpReplaceResponceDone:
                TraceEvents(
                    TRACE_LEVEL_WARNING,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceResponceDone\""
                    );
                goto _elaborate_responce_02;
            case csTcpFlowEstablished:
                TraceEvents(
                    TRACE_LEVEL_WARNING,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpFlowEstablished\""
                    );
                goto _elaborate_query_02;
            default:
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                    );
                break;
            }
            break;
        case csTcpReplaceResponceDone:
            TraceEvents(
                TRACE_LEVEL_WARNING,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceResponceDone\""
                );
            goto _elaborate_responce_02;
        case csTcpPermitResponceDone:
            TraceEvents(
                TRACE_LEVEL_WARNING,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitResponceDone\""
                );
        _elaborate_responce_02:
            wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        case csTcpFlowEstablished:
            TraceEvents(
                TRACE_LEVEL_WARNING,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpFlowEstablished\""
                );
        _elaborate_query_02:
            wdfRequestQueue = pFlowData->wdfWaitDnsQueryQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        default:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                );
            break;
        }
        break;
    case csTcpFlowEstablished:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpFlowEstablished\""
            );
        goto _continue_36;
    case csUdpFlowEstablished:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpFlowEstablished\""
            );
    _continue_36:
        wdfRequestQueue = pFlowData->wdfWaitDnsQueryQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        break;
    case csUdpFlowDone:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpFlowDone\""
            );
        break;
    case csUdpReplaceResponcePended:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpReplaceResponcePended\""
            );
        bListEmpty = RemoveEntryList(&pFlowData->threadListEntry);
        goto _continue_37;
    case csUdpWaitReplaceResponceDone:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReplaceResponceDone\""
            );
    _continue_37:
        pNetBufferList = pFlowData->pUdpResponceReplaceBufferList;
        pFlowData->pUdpResponceReplaceBufferList = NULL;
        if (NULL != pNetBufferList)
        {
            FwpsFreeNetBufferList(
                pNetBufferList
                );
            _pControlData = pFlowData->stUdpResponceSendParams.controlData;
            if (NULL != _pControlData)
            {
                ExFreePoolWithTag(
                    _pControlData,
                    POOL_TAG
                    );
            }
            RtlZeroMemory(
                &pFlowData->stUdpResponceSendParams,
                sizeof(FWPS_TRANSPORT_SEND_PARAMS)
                );
        }
        _pMdl = pFlowData->pUdpResponceMdl;
        pFlowData->pUdpResponceMdl = NULL;
        if (NULL != _pMdl)
        {
            IoFreeMdl(_pMdl);
            ExFreePoolWithTag(
                _pMdl->MappedSystemVa,
                POOL_TAG
                );
        }
        wdfRequestQueue = pFlowData->wdfUdpResponceReplaceQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        break;
    case csUdpWaitReplaceResponce:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReplaceResponce\""
            );
        goto _continue_38;
    case csUdpWaitApprovalResponce:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitApprovalResponce\""
            );
        goto _continue_38;
    case csUdpWaitReadResponce:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReadResponce\""
            );
    _continue_38:
        pNetBufferList = pFlowData->pUdpResponceBufferList;
        pFlowData->pUdpResponceBufferList = NULL;
        if (NULL != pNetBufferList)
        {
            FwpsDereferenceNetBufferList(
                pNetBufferList,
                FALSE
                );
        }
        pNetBufferList = pFlowData->pUdpResponceCloneBufferList;
        pFlowData->pUdpResponceCloneBufferList = NULL;
        if (NULL != pNetBufferList)
        {
            FwpsFreeCloneNetBufferList(
                pNetBufferList,
                0
                );
        }
        _pControlData = pFlowData->stUdpResponceSendParams.controlData;
        if (NULL != _pControlData)
        {
            ExFreePoolWithTag(
                _pControlData,
                POOL_TAG
                );
        }
        RtlZeroMemory(
            &pFlowData->stUdpResponceSendParams,
            sizeof(FWPS_TRANSPORT_SEND_PARAMS)
            );
        break;
    case csUdpPermitResponcePended:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpPermitResponcePended\""
            );
        bListEmpty = RemoveEntryList(&pFlowData->threadListEntry);
        goto _continue_39;
    case csUdpWaitPermitResponce:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitPermitResponce\""
            );
    _continue_39:
        pNetBufferList = pFlowData->pUdpResponceCloneBufferList;
        pFlowData->pUdpResponceCloneBufferList = NULL;
        if (NULL != pNetBufferList)
        {
            FwpsFreeCloneNetBufferList(
                pNetBufferList,
                0
                );
        }
        _pControlData = pFlowData->stUdpResponceSendParams.controlData;
        if (NULL != _pControlData)
        {
            ExFreePoolWithTag(
                _pControlData,
                POOL_TAG
                );
        }
        RtlZeroMemory(
            &pFlowData->stUdpResponceSendParams,
            sizeof(FWPS_TRANSPORT_SEND_PARAMS)
            );
        wdfRequestQueue = pFlowData->wdfUdpResponcePermitQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        break;
    case csUdpWaitQueryInjectDone:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitQueryInjectDone\""
            );
        switch (pFlowData->arContextStateStack[i + 1])
        {
        case csUdpWaitReplaceQueryDone:
            TraceEvents(
                TRACE_LEVEL_WARNING,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitQueryInjectDone\""
                );
            pNetBufferList = pFlowData->pUdpQueryReplaceBufferList;
            pFlowData->pUdpQueryReplaceBufferList = NULL;
            if (NULL != pNetBufferList)
            {
                FwpsFreeNetBufferList(
                    pNetBufferList
                    );
            }
            _pMdl = pFlowData->pUdpQueryMdl;
            pFlowData->pUdpQueryMdl = NULL;
            if (NULL != _pMdl)
            {
                IoFreeMdl(_pMdl);
                ExFreePoolWithTag(
                    _pMdl->MappedSystemVa,
                    POOL_TAG
                    );
            }
            wdfRequestQueue = pFlowData->wdfUdpQueryReplaceQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        case csUdpWaitPermitQuery:
            TraceEvents(
                TRACE_LEVEL_WARNING,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitPermitQuery\""
                );
            pNetBufferList = pFlowData->pUdpQueryCloneBufferList;
            pFlowData->pUdpQueryCloneBufferList = NULL;
            if (NULL != pNetBufferList)
            {
                FwpsFreeCloneNetBufferList(
                    pNetBufferList,
                    0
                    );
            }
            wdfRequestQueue = pFlowData->wdfUdpQueryPermitQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        default:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                );
            break;
        }
        break;
    case csUdpReplaceQueryDone:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpReplaceQueryDone\""
            );
        goto _continue_40;
    case csUdpPermitQueryDone:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpPermitQueryDone\""
            );
    _continue_40:
        wdfRequestQueue = pFlowData->wdfWaitUdpResponceQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        break;
    case csUdpQueryDiscarded:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpQueryDiscarded\""
            );
        break;
    case csUdpReplaceQueryPended:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpReplaceQueryPended\""
            );
        bListEmpty = RemoveEntryList(&pFlowData->threadListEntry);
        goto _continue_41;
    case csUdpWaitReplaceQueryDone:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReplaceQueryDone\""
            );
    _continue_41:
        pNetBufferList = pFlowData->pUdpQueryReplaceBufferList;
        pFlowData->pUdpQueryReplaceBufferList = NULL;
        if (NULL != pNetBufferList)
        {
            FwpsFreeNetBufferList(
                pNetBufferList
                );
        }
        _pMdl = pFlowData->pUdpQueryMdl;
        pFlowData->pUdpQueryMdl = NULL;
        if (NULL != _pMdl)
        {
            IoFreeMdl(_pMdl);
            ExFreePoolWithTag(
                _pMdl->MappedSystemVa,
                POOL_TAG
                );
        }
        wdfRequestQueue = pFlowData->wdfUdpQueryReplaceQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        wdfRequestQueue = pFlowData->wdfWaitUdpResponceQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        break;
    case csUdpWaitReplaceQuery:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReplaceQuery\""
            );
        goto _continue_42;
    case csUdpWaitApprovalQuery:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitApprovalQuery\""
            );
    _continue_42:
        pNetBufferList = pFlowData->pUdpQueryBufferList;
        pFlowData->pUdpQueryBufferList = NULL;
        if (NULL != pNetBufferList)
        {
            FwpsDereferenceNetBufferList(
                pNetBufferList,
                FALSE
                );
        }
        break;
    case csUdpPermitQueryPended:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpPermitQueryPended\""
            );
        bListEmpty = RemoveEntryList(&pFlowData->threadListEntry);
        goto _continue_43;
    case csUdpWaitPermitQuery:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitPermitQuery\""
            );
    _continue_43:
        pNetBufferList = pFlowData->pUdpQueryCloneBufferList;
        pFlowData->pUdpQueryCloneBufferList = NULL;
        if (NULL != pNetBufferList)
        {
            FwpsFreeCloneNetBufferList(
                pNetBufferList,
                0
                );
        }
        wdfRequestQueue = pFlowData->wdfUdpQueryPermitQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        wdfRequestQueue = pFlowData->wdfWaitUdpResponceQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        break;
    case csUdpWaitResponceStarted:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitResponceStarted\""
            );
        pNetBufferList = pFlowData->pUdpQueryBufferList;
        pFlowData->pUdpQueryBufferList = NULL;
        if (NULL != pNetBufferList)
        {
            FwpsDereferenceNetBufferList(
                pNetBufferList,
                FALSE
                );
        }
        wdfRequestQueue = pFlowData->wdfWaitUdpResponceQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        break;
    case csUdpWaitReadQuery:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReadQuery\""
            );
        pNetBufferList = pFlowData->pUdpQueryBufferList;
        pFlowData->pUdpQueryBufferList = NULL;
        if (NULL != pNetBufferList)
        {
            FwpsDereferenceNetBufferList(
                pNetBufferList,
                FALSE
                );
        }
        wdfRequestQueue = pFlowData->wdfWaitFlowEstablishedQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        break;
    case csDnsError:
        TraceEvents(
            TRACE_LEVEL_ERROR,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csDnsError\""
            );
        bErrorState = TRUE;
        for (i = i + 1; i<20; i++)
        {
            if (csDnsError != pFlowData->arContextStateStack[i])
            {
                bStateFinded = TRUE;
                break;
            }
        }
        if (!bStateFinded)
        {
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! Invalid stack of State machine"
                );
            break;
        }
        i++;
        switch (pFlowData->arContextStateStack[i])
        {
        case csTcpReplaceResponceDone:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceResponceDone\""
                );
            goto _continue_44;
        case csTcpPermitResponceDone:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitResponceDone\""
                );
        _continue_44:
            wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        case csTcpWaitPermitResponce:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitPermitResponce\""
                );
        _elaborate_permit_responce_04:
            pNetBufferList = pFlowData->pTcpResponceBufferList;
            pFlowData->pTcpResponceBufferList = NULL;
            if (NULL != pNetBufferList)
            {
                FwpsFreeCloneNetBufferList(
                    pNetBufferList,
                    0
                    );
            }
            wdfRequestQueue = pFlowData->wdfTcpResponcePermitQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        case csTcpWaitReplaceResponceDone:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReplaceResponceDone\""
                );
        _elaborate_replace_responce_04:
            pNetBufferList = pFlowData->pTcpResponceInjectBufferList;
            if (NULL != pNetBufferList)
            {
                FwpsFreeNetBufferList(
                    pNetBufferList
                    );
                pFlowData->pTcpResponceInjectBufferList = NULL;
                _pMdl = pFlowData->pTcpResponceMdl;
                ASSERT(NULL != _pMdl);
                IoFreeMdl(_pMdl);
                ExFreePoolWithTag(
                    _pMdl->MappedSystemVa,
                    POOL_TAG
                    );
                pFlowData->pTcpResponceMdl = NULL;
            }
            wdfRequestQueue = pFlowData->wdfTcpResponceInjectQueue;
            pFlowData->wdfTcpResponceInjectQueue = NULL;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        case csTcpResponceMoreData03:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpResponceMoreData03\""
                );
            bStateFinded = FALSE;
            for (i = i + 1; i<20; i++)
            {
                if (csTcpResponceMoreData03 != pFlowData->arContextStateStack[i])
                {
                    bStateFinded = TRUE;
                    break;
                }
            }
            if (!bStateFinded)
            {
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! Invalid stack of State machine"
                    );
                break;
            }
            switch (pFlowData->arContextStateStack[i])
            {
            case csTcpWaitPermitResponce:
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitPermitResponce\""
                    );
                goto _elaborate_permit_responce_04;
            case csTcpWaitReplaceResponceDone:
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReplaceResponceDone\""
                    );
                goto _elaborate_replace_responce_04;
            default:
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                    );
                break;
            }
            wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        case csTcpPermitQueryDone:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitQueryDone\""
                );
            goto _continue_45;
        case csTcpReplaceQueryDone:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceQueryDone\""
                );
        _continue_45:
            wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        case csTcpWaitPermitQuery:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitPermitQuery\""
                );
        _elaborate_permit_query_03:
            pNetBufferList = pFlowData->pTcpQueryBufferList;
            if (NULL != pNetBufferList)
            {
                FwpsFreeCloneNetBufferList(
                    pNetBufferList,
                    0
                    );
                pFlowData->pTcpQueryBufferList = NULL;
            }
            wdfRequestQueue = pFlowData->wdfTcpQueryPermitQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        case csTcpWaitReplaceQueryDone:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReplaceQueryDone\""
                );
        _elaborate_replace_query_03:
            pNetBufferList = pFlowData->pTcpQueryInjectBufferList;
            if (NULL != pNetBufferList)
            {
                FwpsFreeNetBufferList(
                    pNetBufferList
                    );
                pFlowData->pTcpQueryInjectBufferList = NULL;
                _pMdl = pFlowData->pTcpQueryMdl;
                ASSERT(NULL != _pMdl);
                IoFreeMdl(_pMdl);
                ExFreePoolWithTag(
                    _pMdl->MappedSystemVa,
                    POOL_TAG
                    );
                pFlowData->pTcpQueryMdl = NULL;
            }
            wdfRequestQueue = pFlowData->wdfTcpQueryInjectQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        case csTcpResponceMoreData02:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpResponceMoreData02\""
                );
        _elaborate_more_data02_03:
            bStateFinded = FALSE;
            for (i = i + 1; i<20; i++)
            {
                if (csTcpResponceMoreData02 != pFlowData->arContextStateStack[i])
                {
                    bStateFinded = TRUE;
                    break;
                }
            }
            if (!bStateFinded)
            {
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! Invalid stack of State machine"
                    );
                wdfRequestQueue = NULL;
                break;
            }
            switch (pFlowData->arContextStateStack[i])
            {
            case csTcpWaitPermitQuery:
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitPermitQuery\""
                    );
                goto _elaborate_permit_query_03;
            case csTcpWaitReplaceQueryDone:
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpWaitReplaceQueryDone\""
                    );
                goto _elaborate_replace_query_03;
            default:
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                    );
                break;
            }
            wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        case csTcpResponceMoreData01:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpResponceMoreData01\""
                );
            bStateFinded = FALSE;
            for (i = i + 1; i<20; i++)
            {
                if (csTcpResponceMoreData01 != pFlowData->arContextStateStack[i])
                {
                    bStateFinded = TRUE;
                    break;
                }
            }
            if (!bStateFinded)
            {
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! Invalid stack of State machine"
                    );
                break;
            }
            switch (pFlowData->arContextStateStack[i])
            {
            case csTcpResponceMoreData02:
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpResponceMoreData02\""
                    );
                goto _elaborate_more_data02_03;
            case csTcpPermitQueryDone:
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitQueryDone\""
                    );
                goto _continue_46;
            case csTcpReplaceQueryDone:
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceQueryDone\""
                    );
            _continue_46:
                wdfRequestQueue = pFlowData->wdfWaitTcpResponceQueue;
                pFlowData->wdfWaitTcpResponceQueue = NULL;
                if (NULL != wdfRequestQueue)
                {
                    arRequestQueue[nQueueIndx] = wdfRequestQueue;
                    nQueueIndx++;
                    ASSERT(nQueueIndx < 16);
                }
                break;
            case csTcpPermitResponceDone:
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitResponceDone\""
                    );
                goto _continue_47;
            case csTcpReplaceResponceDone:
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceResponceDone\""
                    );
            _continue_47:
                wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
                if (NULL != wdfRequestQueue)
                {
                    arRequestQueue[nQueueIndx] = wdfRequestQueue;
                    nQueueIndx++;
                    ASSERT(nQueueIndx < 16);
                }
                break;
            default:
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                    );
                break;
            }
            break;
        case csTcpQueryMoreData01:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpQueryMoreData01\""
                );
            for (i = i + 1; i<20; i++)
            {
                if (csTcpQueryMoreData01 != pFlowData->arContextStateStack[i])
                {
                    bStateFinded = TRUE;
                    break;
                }
            }
            if (!bStateFinded)
            {
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! Invalid stack of State machine"
                    );
                break;
            }
            switch (pFlowData->arContextStateStack[i])
            {
            case csTcpFlowEstablished:
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpFlowEstablished\""
                    );
                goto _elaborate_flow_establised_03;
            case csTcpPermitResponceDone:
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpPermitResponceDone\""
                    );
                goto _continue_48;
            case csTcpReplaceResponceDone:
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpReplaceResponceDone\""
                    );
            _continue_48:
                wdfRequestQueue = pFlowData->wdfWaitTcpNewMessageQueue;
                if (NULL != wdfRequestQueue)
                {
                    arRequestQueue[nQueueIndx] = wdfRequestQueue;
                    nQueueIndx++;
                    ASSERT(nQueueIndx < 16);
                }
                break;
            default:
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                    );
                break;
            }
            break;
        case csTcpFlowEstablished:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csTcpFlowEstablished\""
                );
        _elaborate_flow_establised_03:
            wdfRequestQueue = pFlowData->wdfWaitDnsQueryQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        case csUdpReplaceQueryDone:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpReplaceQueryDone\""
                );
            goto _continue_49;
        case csUdpPermitQueryDone:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpPermitQueryDone\""
                );
        _continue_49:
            wdfRequestQueue = pFlowData->wdfWaitUdpResponceQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        case csUdpPermitQueryPended:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpPermitQueryPended\""
                );
            bListEmpty = RemoveEntryList(&pFlowData->threadListEntry);
            goto _continue_50;
        case csUdpWaitPermitQuery:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitPermitQuery\""
                );
        _continue_50:
            pNetBufferList = pFlowData->pUdpQueryCloneBufferList;
            pFlowData->pUdpQueryCloneBufferList = NULL;
            if (NULL != pNetBufferList)
            {
                FwpsFreeCloneNetBufferList(
                    pNetBufferList,
                    0
                    );
            }
            wdfRequestQueue = pFlowData->wdfUdpQueryPermitQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            wdfRequestQueue = pFlowData->wdfWaitUdpResponceQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        case csUdpReplaceQueryPended:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpReplaceQueryPended\""
                );
            bListEmpty = RemoveEntryList(&pFlowData->threadListEntry);
            goto _continue_51;
        case csUdpWaitReplaceQueryDone:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReplaceQueryDone\""
                );
        _continue_51:
            pNetBufferList = pFlowData->pUdpQueryReplaceBufferList;
            pFlowData->pUdpQueryReplaceBufferList = NULL;
            if (NULL != pNetBufferList)
            {
                FwpsFreeNetBufferList(
                    pNetBufferList
                    );
            }
            _pMdl = pFlowData->pUdpQueryMdl;
            pFlowData->pUdpQueryMdl = NULL;
            if (NULL != _pMdl)
            {
                IoFreeMdl(_pMdl);
                ExFreePoolWithTag(
                    _pMdl->MappedSystemVa,
                    POOL_TAG
                    );
            }
            wdfRequestQueue = pFlowData->wdfUdpQueryReplaceQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            wdfRequestQueue = pFlowData->wdfWaitUdpResponceQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        case csUdpWaitResponceStarted:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitResponceStarted\""
                );
            pNetBufferList = pFlowData->pUdpQueryBufferList;
            pFlowData->pUdpQueryBufferList = NULL;
            if (NULL != pNetBufferList)
            {
                FwpsDereferenceNetBufferList(
                    pNetBufferList,
                    FALSE
                    );
            }
            wdfRequestQueue = pFlowData->wdfWaitUdpResponceQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        case csUdpQueryDiscarded:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpQueryDiscarded\""
                );
            break;
        case csUdpWaitQueryInjectDone:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitQueryInjectDone\""
                );
            switch (pFlowData->arContextStateStack[i + 2])
            {
            case csUdpWaitReplaceQueryDone:
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReplaceQueryDone\""
                    );
                pNetBufferList = pFlowData->pUdpQueryReplaceBufferList;
                pFlowData->pUdpQueryReplaceBufferList = NULL;
                if (NULL != pNetBufferList)
                {
                    FwpsFreeNetBufferList(
                        pNetBufferList
                        );
                }
                _pMdl = pFlowData->pUdpQueryMdl;
                pFlowData->pUdpQueryMdl = NULL;
                if (NULL != _pMdl)
                {
                    IoFreeMdl(_pMdl);
                    ExFreePoolWithTag(
                        _pMdl->MappedSystemVa,
                        POOL_TAG
                        );
                }
                wdfRequestQueue = pFlowData->wdfUdpQueryReplaceQueue;
                if (NULL != wdfRequestQueue)
                {
                    arRequestQueue[nQueueIndx] = wdfRequestQueue;
                    nQueueIndx++;
                    ASSERT(nQueueIndx < 16);
                }
                break;
            case csUdpWaitPermitQuery:
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitPermitQuery\""
                    );
                pNetBufferList = pFlowData->pUdpQueryCloneBufferList;
                pFlowData->pUdpQueryCloneBufferList = NULL;
                if (NULL != pNetBufferList)
                {
                    FwpsFreeCloneNetBufferList(
                        pNetBufferList,
                        0
                        );
                }
                wdfRequestQueue = pFlowData->wdfUdpQueryPermitQueue;
                if (NULL != wdfRequestQueue)
                {
                    arRequestQueue[nQueueIndx] = wdfRequestQueue;
                    nQueueIndx++;
                    ASSERT(nQueueIndx < 16);
                }
                break;
            default:
                TraceEvents(
                    TRACE_LEVEL_ERROR,
                    FILE_TRACE,
                    "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                    );
                break;
            }
            break;
        case csUdpWaitReplaceResponce:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReplaceResponce\""
                );
            goto _continue_52;
        case csUdpWaitApprovalResponce:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitApprovalResponce\""
                );
            goto _continue_52;
        case csUdpWaitReadResponce:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReadResponce\""
                );
        _continue_52:
            pNetBufferList = pFlowData->pUdpResponceBufferList;
            pFlowData->pUdpResponceBufferList = NULL;
            if (NULL != pNetBufferList)
            {
                FwpsDereferenceNetBufferList(
                    pNetBufferList,
                    FALSE
                    );
            }
            pNetBufferList = pFlowData->pUdpResponceCloneBufferList;
            pFlowData->pUdpResponceCloneBufferList = NULL;
            if (NULL != pNetBufferList)
            {
                FwpsFreeCloneNetBufferList(
                    pNetBufferList,
                    0
                    );
            }
            _pControlData = pFlowData->stUdpResponceSendParams.controlData;
            if (NULL != _pControlData)
            {
                ExFreePoolWithTag(
                    _pControlData,
                    POOL_TAG
                    );
            }
            RtlZeroMemory(
                &pFlowData->stUdpResponceSendParams,
                sizeof(FWPS_TRANSPORT_SEND_PARAMS)
                );
            break;
        case csUdpPermitResponcePended:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpPermitResponcePended\""
                );
            bListEmpty = RemoveEntryList(&pFlowData->threadListEntry);
            goto _continue_53;
        case csUdpWaitPermitResponce:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitPermitResponce\""
                );
        _continue_53:
            pNetBufferList = pFlowData->pUdpResponceCloneBufferList;
            pFlowData->pUdpResponceCloneBufferList = NULL;
            if (NULL != pNetBufferList)
            {
                FwpsFreeCloneNetBufferList(
                    pNetBufferList,
                    0
                    );
            }
            _pControlData = pFlowData->stUdpResponceSendParams.controlData;
            if (NULL != _pControlData)
            {
                ExFreePoolWithTag(
                    _pControlData,
                    POOL_TAG
                    );
            }
            RtlZeroMemory(
                &pFlowData->stUdpResponceSendParams,
                sizeof(FWPS_TRANSPORT_SEND_PARAMS)
                );
            wdfRequestQueue = pFlowData->wdfUdpResponcePermitQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        case csUdpReplaceResponcePended:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpReplaceResponcePended\""
                );
            bListEmpty = RemoveEntryList(&pFlowData->threadListEntry);
            goto _continue_54;
        case csUdpWaitReplaceResponceDone:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReplaceResponceDone\""
                );
        _continue_54:
            pNetBufferList = pFlowData->pUdpResponceReplaceBufferList;
            pFlowData->pUdpResponceReplaceBufferList = NULL;
            if (NULL != pNetBufferList)
            {
                FwpsFreeNetBufferList(
                    pNetBufferList
                    );
                _pControlData = pFlowData->stUdpResponceSendParams.controlData;
                if (NULL != _pControlData)
                {
                    ExFreePoolWithTag(
                        _pControlData,
                        POOL_TAG
                        );
                }
                RtlZeroMemory(
                    &pFlowData->stUdpResponceSendParams,
                    sizeof(FWPS_TRANSPORT_SEND_PARAMS)
                    );
            }
            _pMdl = pFlowData->pUdpResponceMdl;
            pFlowData->pUdpResponceMdl = NULL;
            if (NULL != _pMdl)
            {
                IoFreeMdl(_pMdl);
                ExFreePoolWithTag(
                    _pMdl->MappedSystemVa,
                    POOL_TAG
                    );
            }
            wdfRequestQueue = pFlowData->wdfUdpResponceReplaceQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        case csUdpWaitReplaceQuery:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReplaceQuery\""
                );
            goto _continue_55;
        case csUdpWaitApprovalQuery:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitApprovalQuery\""
                );
        _continue_55:
            pNetBufferList = pFlowData->pUdpQueryBufferList;
            pFlowData->pUdpQueryBufferList = NULL;
            if (NULL != pNetBufferList)
            {
                FwpsDereferenceNetBufferList(
                    pNetBufferList,
                    FALSE
                    );
            }
            break;
        case csUdpWaitReadQuery:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpWaitReadQuery\""
                );
            pNetBufferList = pFlowData->pUdpQueryBufferList;
            pFlowData->pUdpQueryBufferList = NULL;
            if (NULL != pNetBufferList)
            {
                FwpsDereferenceNetBufferList(
                    pNetBufferList,
                    FALSE
                    );
            }
            wdfRequestQueue = pFlowData->wdfWaitFlowEstablishedQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        case csUdpFlowEstablished:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                TRACE_DNSFILTER,
                "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csUdpFlowEstablished\""
                );
            wdfRequestQueue = pFlowData->wdfWaitDnsQueryQueue;
            if (NULL != wdfRequestQueue)
            {
                arRequestQueue[nQueueIndx] = wdfRequestQueue;
                nQueueIndx++;
                ASSERT(nQueueIndx < 16);
            }
            break;
        default:
            TraceEvents(
                TRACE_LEVEL_ERROR,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
                );
            break;
        }
        break;
    case csWaitFlowEstablishedStarted:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csWaitFlowEstablishedStarted\""
            );
        wdfRequestQueue = pFlowData->wdfWaitFlowEstablishedQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        bListEmpty = RemoveEntryList(
            &pFlowData->listEntry
            );
        wdfRequestQueue = pFlowData->wdfWaitDnsQueryQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        break;
    case csWaitFlowDoneStarted:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csWaitFlowDoneStarted\""
            );
        goto _continue_56;
    case csWaitQueryStarted:
        TraceEvents(
            TRACE_LEVEL_WARNING,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! State of the State machine is \"csWaitQueryStarted\""
            );
    _continue_56:
        wdfRequestQueue = pFlowData->wdfWaitDnsQueryQueue;
        if (NULL != wdfRequestQueue)
        {
            arRequestQueue[nQueueIndx] = wdfRequestQueue;
            nQueueIndx++;
            ASSERT(nQueueIndx < 16);
        }
        break;
    default:
        TraceEvents(
            TRACE_LEVEL_ERROR,
            FILE_TRACE,
            "%!FUNC! line:%!LINE! %!LEVEL! Invalid State Superintendent of State machine"
            );
        break;
    }
    if (!bErrorState)
    {
        if (0 != ullFlowId)
        {
            WdfObjectReleaseLock(wdfDeviceObject);
            if (IPPROTO_TCP == pFlowData->enIpProto)
            {
                if (pFlowData->bIPv6)
                {
                    status = FwpsFlowRemoveContext(
                        ullFlowId,
                        FWPS_LAYER_STREAM_V6,
                        g_nStreamIdV6
                        );
                }
                else
                {
                    status = FwpsFlowRemoveContext(
                        ullFlowId,
                        FWPS_LAYER_STREAM_V4,
                        g_nStreamId
                        );
                }
            }
            else if (IPPROTO_UDP == pFlowData->enIpProto)
            {
                if (pFlowData->bIPv6)
                {
                    status = FwpsFlowRemoveContext(
                        ullFlowId,
                        FWPS_LAYER_DATAGRAM_DATA_V6,
                        g_nDatagramIdV6
                        );
                }
                else
                {
                    status = FwpsFlowRemoveContext(
                        ullFlowId,
                        FWPS_LAYER_DATAGRAM_DATA_V4,
                        g_nDatagramId
                        );
                }
            }
            else
            {
                ASSERT(FALSE);
            }
            TraceEvents(
                TRACE_LEVEL_WARNING,
                FILE_TRACE,
                "%!FUNC! line:%!LINE! %!LEVEL! \"FwpsFlowRemoveContext\" return %!STATUS!",
                status
                );
            WdfObjectAcquireLock(wdfDeviceObject);
            if ((STATUS_SUCCESS == status) || (STATUS_PENDING == status))
            {
                wdfPurgedQueue = pFlowData->wdfFlowQueue;
                pFlowData->wdfFlowQueue = NULL;
                if (NULL != wdfPurgedQueue)
                {
                    WdfIoQueuePurge(
                        wdfPurgedQueue,
                        NULL,
                        NULL
                        );
                    WdfObjectDelete(
                        wdfPurgedQueue
                        );
                }
                pFlowData->enContextState = csFileClosed;
                push_css(pFlowData->arContextStateStack, pFlowData->enContextState);
                {
                    PLIST_ENTRY PrevEntry;
                    PLIST_ENTRY NextEntry;
                    PLIST_ENTRY Entry = &pFlowData->stFileListEntry;
                    NextEntry = Entry->Flink;
                    PrevEntry = Entry->Blink;
                    if ((NextEntry->Blink == Entry) && (PrevEntry->Flink == Entry))
                    {
                        bListEmpty = RemoveEntryList(Entry);
                    }
                }
                pFlowData->pThis = NULL;
                pFlowData->wdfFlowFileObject = NULL;
                WdfObjectReleaseLock(wdfDeviceObject);
                return;
            }
            status1 = status;
            wdfRequestQueue = pFlowData->wdfWaitFlowDoneQueue;
            pFlowData->wdfWaitFlowDoneQueue = NULL;
            if (NULL != wdfRequestQueue)
            {
                status = WdfIoQueueRetrieveNextRequest(
                    wdfRequestQueue,
                    &wdfPendedRequest
                    );
                if (NT_SUCCESS(status))
                {
                    status = WdfRequestRetrieveOutputMemory(
                        wdfPendedRequest,
                        &wdfOutputMemory
                        );
                    ASSERT(NT_SUCCESS(status));
                    status = WdfMemoryCopyFromBuffer(
                        wdfOutputMemory,
                        0,
                        pFlowData,
                        sizeof(FLOW_DATA)
                        );
                    ASSERT(NT_SUCCESS(status));
                    WdfRequestCompleteWithInformation(
                        wdfPendedRequest,
                        status1,
                        sizeof(FLOW_DATA)
                        );
                }
                WdfObjectDelete(wdfRequestQueue);
            }
        }
        for (i = 0; i < nQueueIndx; i++)
        {
            status = WdfIoQueueRetrieveNextRequest(
                wdfRequestQueue,
                &wdfPendedRequest
                );
            if (NT_SUCCESS(status))
            {
                WdfRequestCompleteWithInformation(
                    wdfPendedRequest,
                    STATUS_CANCELLED,
                    0
                    );
            }
            WdfObjectDelete(wdfRequestQueue);
        }
        wdfPurgedQueue = pFlowData->wdfFlowQueue;
        pFlowData->wdfFlowQueue = NULL;
        if (NULL != wdfPurgedQueue)
        {
            WdfIoQueuePurge(
                wdfPurgedQueue,
                NULL,
                NULL
                );
            WdfObjectDelete(
                wdfPurgedQueue
                );
        }
        pFlowData->enContextState = csFileClosed;
        push_css(pFlowData->arContextStateStack, pFlowData->enContextState);
        {
            PLIST_ENTRY PrevEntry;
            PLIST_ENTRY NextEntry;
            PLIST_ENTRY Entry = &pFlowData->stFileListEntry;
            NextEntry = Entry->Flink;
            PrevEntry = Entry->Blink;
            if ((NextEntry->Blink == Entry) && (PrevEntry->Flink == Entry))
            {
                bListEmpty = RemoveEntryList(Entry);
            }
        }
        pFlowData->pThis = NULL;
        pFlowData->wdfFlowFileObject = NULL;
        WdfObjectReleaseLock(wdfDeviceObject);
        return;
    }
    for (i = 0; i < nQueueIndx; i++)
    {
        status = WdfIoQueueRetrieveNextRequest(
            wdfRequestQueue,
            &wdfPendedRequest
            );
        if (NT_SUCCESS(status))
        {
            WdfRequestCompleteWithInformation(
                wdfPendedRequest,
                STATUS_CANCELLED,
                0
                );
        }
        WdfObjectDelete(wdfRequestQueue);
    }
    wdfPurgedQueue = pFlowData->wdfFlowQueue;
    pFlowData->wdfFlowQueue = NULL;
    if (NULL != wdfPurgedQueue)
    {
        WdfIoQueuePurge(
            wdfPurgedQueue,
            NULL,
            NULL
            );
        WdfObjectDelete(
            wdfPurgedQueue
            );
    }
    pFlowData->enContextState = csFileClosed;
    push_css(pFlowData->arContextStateStack, pFlowData->enContextState);
    {
        PLIST_ENTRY PrevEntry;
        PLIST_ENTRY NextEntry;
        PLIST_ENTRY Entry = &pFlowData->stFileListEntry;
        NextEntry = Entry->Flink;
        PrevEntry = Entry->Blink;
        if ((NextEntry->Blink == Entry) && (PrevEntry->Flink == Entry))
        {
            bListEmpty = RemoveEntryList(Entry);
        }
    }
    pFlowData->pThis = NULL;
    pFlowData->wdfFlowFileObject = NULL;
    WdfObjectReleaseLock(wdfDeviceObject);
    TraceEvents(
        TRACE_LEVEL_INFORMATION,
        FILE_TRACE,
        "%!FUNC! line:%!LINE! %!LEVEL! Exit"
        );
}
